github.com/matrixorigin/matrixone@v0.7.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(dir string) fileservice.FileService {
    32  	c := fileservice.Config{
    33  		Name:    defines.LocalFileServiceName,
    34  		Backend: "DISK",
    35  		DataDir: dir,
    36  	}
    37  	service, err := fileservice.NewFileService(c)
    38  	if err != nil {
    39  		err = moerr.NewInternalErrorNoCtx(fmt.Sprintf("NewFileService failed: %s", err.Error()))
    40  		panic(any(err))
    41  	}
    42  	return service
    43  }
    44  
    45  func NewObjectFS(service fileservice.FileService, dir string) *ObjectFS {
    46  	fs := &ObjectFS{
    47  		Service: service,
    48  		Dir:     dir,
    49  	}
    50  	return fs
    51  }
    52  
    53  func (o *ObjectFS) ListDir(dir string) ([]fileservice.DirEntry, error) {
    54  	return o.Service.List(context.Background(), dir)
    55  }
    56  
    57  func (o *ObjectFS) DelFiles(ctx context.Context, name []string) error {
    58  	return o.Service.Delete(ctx, name...)
    59  }
    60  
    61  func (o *ObjectFS) Delete(fileName string) error {
    62  	return o.Service.Delete(context.Background(), fileName)
    63  }