Skip to content

Commit

Permalink
chore: rename local struct
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jul 19, 2022
1 parent fe94016 commit 638db77
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions drivers/local/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import (
"github.com/pkg/errors"
)

type Driver struct {
type Local struct {
model.Storage
Addition
}

func (d *Driver) Config() driver.Config {
func (d *Local) Config() driver.Config {
return config
}

func (d *Driver) Init(ctx context.Context, storage model.Storage) error {
func (d *Local) Init(ctx context.Context, storage model.Storage) error {
d.Storage = storage
err := utils.Json.UnmarshalFromString(d.Storage.Addition, &d.Addition)
if err != nil {
Expand All @@ -46,15 +46,15 @@ func (d *Driver) Init(ctx context.Context, storage model.Storage) error {
return err
}

func (d *Driver) Drop(ctx context.Context) error {
func (d *Local) Drop(ctx context.Context) error {
return nil
}

func (d *Driver) GetAddition() driver.Additional {
func (d *Local) GetAddition() driver.Additional {
return d.Addition
}

func (d *Driver) List(ctx context.Context, dir model.Obj) ([]model.Obj, error) {
func (d *Local) List(ctx context.Context, dir model.Obj) ([]model.Obj, error) {
fullPath := dir.GetID()
rawFiles, err := ioutil.ReadDir(fullPath)
if err != nil {
Expand All @@ -76,7 +76,7 @@ func (d *Driver) List(ctx context.Context, dir model.Obj) ([]model.Obj, error) {
return files, nil
}

func (d *Driver) Get(ctx context.Context, path string) (model.Obj, error) {
func (d *Local) Get(ctx context.Context, path string) (model.Obj, error) {
f, err := os.Stat(path)
if err != nil {
return nil, errors.Wrapf(err, "error while stat %s", path)
Expand All @@ -91,15 +91,15 @@ func (d *Driver) Get(ctx context.Context, path string) (model.Obj, error) {
return &file, nil
}

func (d *Driver) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
func (d *Local) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
fullPath := file.GetID()
link := model.Link{
FilePath: &fullPath,
}
return &link, nil
}

func (d *Driver) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
func (d *Local) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
fullPath := filepath.Join(parentDir.GetID(), dirName)
err := os.MkdirAll(fullPath, 0700)
if err != nil {
Expand All @@ -108,7 +108,7 @@ func (d *Driver) MakeDir(ctx context.Context, parentDir model.Obj, dirName strin
return nil
}

func (d *Driver) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
func (d *Local) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
srcPath := srcObj.GetID()
dstPath := filepath.Join(dstDir.GetID(), srcObj.GetName())
err := os.Rename(srcPath, dstPath)
Expand All @@ -118,7 +118,7 @@ func (d *Driver) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
return nil
}

func (d *Driver) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
func (d *Local) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
srcPath := srcObj.GetID()
dstPath := filepath.Join(filepath.Dir(srcPath), newName)
err := os.Rename(srcPath, dstPath)
Expand All @@ -128,7 +128,7 @@ func (d *Driver) Rename(ctx context.Context, srcObj model.Obj, newName string) e
return nil
}

func (d *Driver) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
func (d *Local) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
srcPath := srcObj.GetID()
dstPath := filepath.Join(dstDir.GetID(), srcObj.GetName())
var err error
Expand All @@ -143,7 +143,7 @@ func (d *Driver) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
return nil
}

func (d *Driver) Remove(ctx context.Context, obj model.Obj) error {
func (d *Local) Remove(ctx context.Context, obj model.Obj) error {
var err error
if obj.IsDir() {
err = os.RemoveAll(obj.GetID())
Expand All @@ -156,7 +156,7 @@ func (d *Driver) Remove(ctx context.Context, obj model.Obj) error {
return nil
}

func (d *Driver) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
func (d *Local) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
fullPath := filepath.Join(dstDir.GetID(), stream.GetName())
out, err := os.Create(fullPath)
if err != nil {
Expand All @@ -175,8 +175,8 @@ func (d *Driver) Put(ctx context.Context, dstDir model.Obj, stream model.FileStr
return nil
}

func (d *Driver) Other(ctx context.Context, data interface{}) (interface{}, error) {
func (d *Local) Other(ctx context.Context, data interface{}) (interface{}, error) {
return nil, errs.NotSupport
}

var _ driver.Driver = (*Driver)(nil)
var _ driver.Driver = (*Local)(nil)
2 changes: 1 addition & 1 deletion drivers/local/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var config = driver.Config{
}

func New() driver.Driver {
return &Driver{}
return &Local{}
}

func init() {
Expand Down

0 comments on commit 638db77

Please sign in to comment.