github.com/matrixorigin/matrixone@v1.2.0/pkg/objectio/fs.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package objectio 16 17 import ( 18 "context" 19 "fmt" 20 21 "github.com/matrixorigin/matrixone/pkg/common/moerr" 22 "github.com/matrixorigin/matrixone/pkg/defines" 23 "github.com/matrixorigin/matrixone/pkg/fileservice" 24 ) 25 26 type ObjectFS struct { 27 Service fileservice.FileService 28 Dir string 29 } 30 31 func TmpNewFileservice(ctx context.Context, dir string) fileservice.FileService { 32 c := fileservice.Config{ 33 Name: defines.LocalFileServiceName, 34 Backend: "DISK", 35 DataDir: dir, 36 Cache: fileservice.DisabledCacheConfig, 37 } 38 service, err := fileservice.NewFileService(ctx, c, nil) 39 if err != nil { 40 err = moerr.NewInternalErrorNoCtx(fmt.Sprintf("NewFileService failed: %s", err.Error())) 41 panic(any(err)) 42 } 43 return service 44 } 45 46 func NewObjectFS(service fileservice.FileService, dir string) *ObjectFS { 47 fs := &ObjectFS{ 48 Service: service, 49 Dir: dir, 50 } 51 return fs 52 } 53 54 func (o *ObjectFS) ListDir(dir string) ([]fileservice.DirEntry, error) { 55 return o.Service.List(context.Background(), dir) 56 } 57 58 func (o *ObjectFS) DelFiles(ctx context.Context, name []string) error { 59 return o.Service.Delete(ctx, name...) 60 } 61 62 func (o *ObjectFS) Delete(fileName string) error { 63 return o.Service.Delete(context.Background(), fileName) 64 }