diff --git a/cmd/lang.go b/cmd/lang.go index e376b1d9..6b15a291 100644 --- a/cmd/lang.go +++ b/cmd/lang.go @@ -12,7 +12,7 @@ import ( _ "github.com/alist-org/alist/v3/drivers" "github.com/alist-org/alist/v3/internal/bootstrap/data" "github.com/alist-org/alist/v3/internal/conf" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/spf13/cobra" ) @@ -37,7 +37,7 @@ func convert(s string) string { func generateDriversJson() { drivers := make(Drivers) drivers["drivers"] = make(KV[interface{}]) - driverInfoMap := operations.GetDriverInfoMap() + driverInfoMap := op.GetDriverInfoMap() for k, v := range driverInfoMap { drivers["drivers"][k] = convert(k) items := make(KV[interface{}]) diff --git a/drivers/aliyundrive/driver.go b/drivers/aliyundrive/driver.go index 0907ff57..6d8c9047 100644 --- a/drivers/aliyundrive/driver.go +++ b/drivers/aliyundrive/driver.go @@ -48,7 +48,7 @@ func (d *AliDrive) Init(ctx context.Context, storage model.Storage) error { return err } // TODO login / refresh token - //operations.MustSaveDriverStorage(d) + //op.MustSaveDriverStorage(d) err = d.refreshToken() if err != nil { return err diff --git a/drivers/aliyundrive/meta.go b/drivers/aliyundrive/meta.go index 059dd53c..76997898 100644 --- a/drivers/aliyundrive/meta.go +++ b/drivers/aliyundrive/meta.go @@ -2,7 +2,7 @@ package local import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -23,5 +23,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/drivers/aliyundrive/util.go b/drivers/aliyundrive/util.go index 61c58ec1..f85dd78f 100644 --- a/drivers/aliyundrive/util.go +++ b/drivers/aliyundrive/util.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/alist-org/alist/v3/drivers/base" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/go-resty/resty/v2" ) @@ -30,7 +30,7 @@ func (d *AliDrive) refreshToken() error { return fmt.Errorf("failed to refresh token: %s", e.Message) } d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return nil } diff --git a/drivers/local/driver.go b/drivers/local/driver.go index afff61a9..db291790 100644 --- a/drivers/local/driver.go +++ b/drivers/local/driver.go @@ -18,7 +18,7 @@ import ( "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/server/common" "github.com/disintegration/imaging" @@ -49,7 +49,7 @@ func (d *Local) Init(ctx context.Context, storage model.Storage) error { } } } - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return err } diff --git a/drivers/local/meta.go b/drivers/local/meta.go index 0935ec83..e442929e 100644 --- a/drivers/local/meta.go +++ b/drivers/local/meta.go @@ -2,7 +2,7 @@ package local import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -23,5 +23,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/drivers/onedrive/meta.go b/drivers/onedrive/meta.go index 7e4abe4a..fc77c506 100644 --- a/drivers/onedrive/meta.go +++ b/drivers/onedrive/meta.go @@ -2,7 +2,7 @@ package onedrive import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -27,5 +27,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/drivers/onedrive/util.go b/drivers/onedrive/util.go index 0b60c0d0..91f7514f 100644 --- a/drivers/onedrive/util.go +++ b/drivers/onedrive/util.go @@ -14,7 +14,7 @@ import ( "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/go-resty/resty/v2" jsoniter "github.com/json-iterator/go" @@ -92,7 +92,7 @@ func (d *Onedrive) _refreshToken() error { return errs.EmptyToken } d.RefreshToken, d.AccessToken = resp.RefreshToken, resp.AccessToken - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return nil } diff --git a/drivers/pikpak/meta.go b/drivers/pikpak/meta.go index 6d568e64..07ec905a 100644 --- a/drivers/pikpak/meta.go +++ b/drivers/pikpak/meta.go @@ -2,7 +2,7 @@ package local import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -22,5 +22,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/drivers/pikpak/util.go b/drivers/pikpak/util.go index b7e84b41..094435d5 100644 --- a/drivers/pikpak/util.go +++ b/drivers/pikpak/util.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/alist-org/alist/v3/drivers/base" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/go-resty/resty/v2" jsoniter "github.com/json-iterator/go" ) @@ -46,7 +46,7 @@ func (d *PikPak) refreshToken() error { }).Post(url) if err != nil { d.Status = err.Error() - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return err } if e.ErrorCode != 0 { @@ -55,14 +55,14 @@ func (d *PikPak) refreshToken() error { return d.login() } d.Status = e.Error - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return errors.New(e.Error) } data := res.Body() d.Status = "work" d.RefreshToken = jsoniter.Get(data, "refresh_token").ToString() d.AccessToken = jsoniter.Get(data, "access_token").ToString() - operations.MustSaveDriverStorage(d) + op.MustSaveDriverStorage(d) return nil } diff --git a/drivers/template/driver.go b/drivers/template/driver.go index a10eed4c..6dc9c480 100644 --- a/drivers/template/driver.go +++ b/drivers/template/driver.go @@ -29,7 +29,7 @@ func (d *Template) Init(ctx context.Context, storage model.Storage) error { return err } // TODO login / refresh token - //operations.MustSaveDriverStorage(d) + //op.MustSaveDriverStorage(d) return err } diff --git a/drivers/template/meta.go b/drivers/template/meta.go index 86ff7eba..e66ae7a5 100644 --- a/drivers/template/meta.go +++ b/drivers/template/meta.go @@ -2,7 +2,7 @@ package local import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -29,5 +29,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/drivers/virtual/meta.go b/drivers/virtual/meta.go index 18ea998a..f93286f8 100644 --- a/drivers/virtual/meta.go +++ b/drivers/virtual/meta.go @@ -2,7 +2,7 @@ package virtual import ( "github.com/alist-org/alist/v3/internal/driver" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) type Addition struct { @@ -26,5 +26,5 @@ func New() driver.Driver { } func init() { - operations.RegisterDriver(config, New) + op.RegisterDriver(config, New) } diff --git a/internal/aria2/add.go b/internal/aria2/add.go index 5db5af3b..4eb83f3d 100644 --- a/internal/aria2/add.go +++ b/internal/aria2/add.go @@ -7,7 +7,7 @@ import ( "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/errs" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/task" "github.com/google/uuid" "github.com/pkg/errors" @@ -15,7 +15,7 @@ import ( func AddURI(ctx context.Context, uri string, dstDirPath string) error { // check storage - storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath) + storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) if err != nil { return errors.WithMessage(err, "failed get storage") } @@ -24,7 +24,7 @@ func AddURI(ctx context.Context, uri string, dstDirPath string) error { return errors.WithStack(errs.UploadNotSupported) } // check path is valid - obj, err := operations.Get(ctx, storage, dstDirActualPath) + obj, err := op.Get(ctx, storage, dstDirActualPath) if err != nil { if !errs.IsObjectNotFound(err) { return errors.WithMessage(err, "failed get object") diff --git a/internal/aria2/aria2_test.go b/internal/aria2/aria2_test.go index e52896cf..eb52ba25 100644 --- a/internal/aria2/aria2_test.go +++ b/internal/aria2/aria2_test.go @@ -10,7 +10,7 @@ import ( conf2 "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/task" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -39,7 +39,7 @@ func TestConnect(t *testing.T) { func TestDown(t *testing.T) { TestConnect(t) - err := operations.CreateStorage(context.Background(), model.Storage{ + err := op.CreateStorage(context.Background(), model.Storage{ ID: 0, MountPath: "/", Index: 0, diff --git a/internal/aria2/monitor.go b/internal/aria2/monitor.go index 41bcdd4f..1998b614 100644 --- a/internal/aria2/monitor.go +++ b/internal/aria2/monitor.go @@ -11,7 +11,7 @@ import ( "time" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/task" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -114,7 +114,7 @@ var TransferTaskManager = task.NewTaskManager(3, func(k *uint64) { func (m *Monitor) Complete() error { // check dstDir again - storage, dstDirActualPath, err := operations.GetStorageAndActualPath(m.dstDirPath) + storage, dstDirActualPath, err := op.GetStorageAndActualPath(m.dstDirPath) if err != nil { return errors.WithMessage(err, "failed get storage") } @@ -158,7 +158,7 @@ func (m *Monitor) Complete() error { ReadCloser: f, Mimetype: mimetype, } - return operations.Put(tsk.Ctx, storage, dstDirActualPath, stream, tsk.SetProgress) + return op.Put(tsk.Ctx, storage, dstDirActualPath, stream, tsk.SetProgress) }, })) } diff --git a/internal/bootstrap/data/dev.go b/internal/bootstrap/data/dev.go index 1608d6b6..97a5fc37 100644 --- a/internal/bootstrap/data/dev.go +++ b/internal/bootstrap/data/dev.go @@ -7,12 +7,12 @@ import ( "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/message" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" log "github.com/sirupsen/logrus" ) func initDevData() { - err := operations.CreateStorage(context.Background(), model.Storage{ + err := op.CreateStorage(context.Background(), model.Storage{ MountPath: "/", Index: 0, Driver: "local", diff --git a/internal/bootstrap/storage.go b/internal/bootstrap/storage.go index ac3a532d..44af99c5 100644 --- a/internal/bootstrap/storage.go +++ b/internal/bootstrap/storage.go @@ -6,7 +6,7 @@ import ( "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" ) @@ -17,7 +17,7 @@ func LoadStorages() { } go func(storages []model.Storage) { for i := range storages { - err := operations.LoadStorage(context.Background(), storages[i]) + err := op.LoadStorage(context.Background(), storages[i]) if err != nil { utils.Log.Errorf("failed get enabled storages: %+v", err) } else { diff --git a/internal/db/storage.go b/internal/db/storage.go index 73376e72..cd768c4d 100644 --- a/internal/db/storage.go +++ b/internal/db/storage.go @@ -8,8 +8,8 @@ import ( ) // why don't need `cache` for storage? -// because all storage store in `operations.storagesMap` -// the most of the read operation is from `operations.storagesMap` +// because all storage store in `op.storagesMap` +// the most of the read operation is from `op.storagesMap` // just for persistence in database // CreateStorage just insert storage to database diff --git a/internal/fs/copy.go b/internal/fs/copy.go index 22e8361b..825a3b1a 100644 --- a/internal/fs/copy.go +++ b/internal/fs/copy.go @@ -8,7 +8,7 @@ import ( "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/task" "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" @@ -21,17 +21,17 @@ var CopyTaskManager = task.NewTaskManager(3, func(tid *uint64) { // Copy if in the same storage, call move method // if not, add copy task func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) { - srcStorage, srcObjActualPath, err := operations.GetStorageAndActualPath(srcObjPath) + srcStorage, srcObjActualPath, err := op.GetStorageAndActualPath(srcObjPath) if err != nil { return false, errors.WithMessage(err, "failed get src storage") } - dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath) + dstStorage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) if err != nil { return false, errors.WithMessage(err, "failed get dst storage") } // copy if in the same storage, just call driver.Copy if srcStorage.GetStorage() == dstStorage.GetStorage() { - return false, operations.Copy(ctx, srcStorage, srcObjActualPath, dstDirActualPath) + return false, op.Copy(ctx, srcStorage, srcObjActualPath, dstDirActualPath) } // not in the same storage CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{ @@ -45,13 +45,13 @@ func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) { func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcObjPath, dstDirPath string) error { t.SetStatus("getting src object") - srcObj, err := operations.Get(t.Ctx, srcStorage, srcObjPath) + srcObj, err := op.Get(t.Ctx, srcStorage, srcObjPath) if err != nil { return errors.WithMessagef(err, "failed get src [%s] file", srcObjPath) } if srcObj.IsDir() { t.SetStatus("src object is dir, listing objs") - objs, err := operations.List(t.Ctx, srcStorage, srcObjPath, model.ListArgs{}) + objs, err := op.List(t.Ctx, srcStorage, srcObjPath, model.ListArgs{}) if err != nil { return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath) } @@ -80,11 +80,11 @@ func copyBetween2Storages(t *task.Task[uint64], srcStorage, dstStorage driver.Dr } func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcFilePath, dstDirPath string) error { - srcFile, err := operations.Get(tsk.Ctx, srcStorage, srcFilePath) + srcFile, err := op.Get(tsk.Ctx, srcStorage, srcFilePath) if err != nil { return errors.WithMessagef(err, "failed get src [%s] file", srcFilePath) } - link, _, err := operations.Link(tsk.Ctx, srcStorage, srcFilePath, model.LinkArgs{}) + link, _, err := op.Link(tsk.Ctx, srcStorage, srcFilePath, model.LinkArgs{}) if err != nil { return errors.WithMessagef(err, "failed get [%s] link", srcFilePath) } @@ -92,5 +92,5 @@ func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage dri if err != nil { return errors.WithMessagef(err, "failed get [%s] stream", srcFilePath) } - return operations.Put(tsk.Ctx, dstStorage, dstDirPath, stream, tsk.SetProgress) + return op.Put(tsk.Ctx, dstStorage, dstDirPath, stream, tsk.SetProgress) } diff --git a/internal/fs/fs.go b/internal/fs/fs.go index ab0c044e..060f2cfa 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -5,13 +5,13 @@ import ( "github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" log "github.com/sirupsen/logrus" ) // the param named path of functions in this package is a virtual path // So, the purpose of this package is to convert virtual path to actual path -// then pass the actual path to the operations package +// then pass the actual path to the op package func List(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) { res, err := list(ctx, path, refresh...) @@ -97,7 +97,7 @@ func PutAsTask(dstDirPath string, file model.FileStreamer) error { } func GetStorage(path string) (driver.Driver, error) { - storageDriver, _, err := operations.GetStorageAndActualPath(path) + storageDriver, _, err := op.GetStorageAndActualPath(path) if err != nil { return nil, err } diff --git a/internal/fs/get.go b/internal/fs/get.go index 674222b1..fb30e77c 100644 --- a/internal/fs/get.go +++ b/internal/fs/get.go @@ -6,7 +6,7 @@ import ( "time" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" ) @@ -15,14 +15,14 @@ func get(ctx context.Context, path string) (model.Obj, error) { path = utils.StandardizePath(path) // maybe a virtual file if path != "/" { - virtualFiles := operations.GetStorageVirtualFilesByPath(stdpath.Dir(path)) + virtualFiles := op.GetStorageVirtualFilesByPath(stdpath.Dir(path)) for _, f := range virtualFiles { if f.GetName() == stdpath.Base(path) { return f, nil } } } - storage, actualPath, err := operations.GetStorageAndActualPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) if err != nil { // if there are no storage prefix with path, maybe root folder if path == "/" { @@ -35,5 +35,5 @@ func get(ctx context.Context, path string) (model.Obj, error) { } return nil, errors.WithMessage(err, "failed get storage") } - return operations.Get(ctx, storage, actualPath) + return op.Get(ctx, storage, actualPath) } diff --git a/internal/fs/link.go b/internal/fs/link.go index ceae7fc3..e8c73a79 100644 --- a/internal/fs/link.go +++ b/internal/fs/link.go @@ -4,14 +4,14 @@ import ( "context" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/pkg/errors" ) func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) { - storage, actualPath, err := operations.GetStorageAndActualPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) if err != nil { return nil, nil, errors.WithMessage(err, "failed get storage") } - return operations.Link(ctx, storage, actualPath, args) + return op.Link(ctx, storage, actualPath, args) } diff --git a/internal/fs/list.go b/internal/fs/list.go index 824020d5..d5800bc9 100644 --- a/internal/fs/list.go +++ b/internal/fs/list.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -16,15 +16,15 @@ import ( func list(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) { meta := ctx.Value("meta").(*model.Meta) user := ctx.Value("user").(*model.User) - storage, actualPath, err := operations.GetStorageAndActualPath(path) - virtualFiles := operations.GetStorageVirtualFilesByPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) + virtualFiles := op.GetStorageVirtualFilesByPath(path) if err != nil { if len(virtualFiles) != 0 { return virtualFiles, nil } return nil, errors.WithMessage(err, "failed get storage") } - objs, err := operations.List(ctx, storage, actualPath, model.ListArgs{ + objs, err := op.List(ctx, storage, actualPath, model.ListArgs{ ReqPath: path, }, refresh...) if err != nil { diff --git a/internal/fs/other.go b/internal/fs/other.go index 107d49a0..f71cf576 100644 --- a/internal/fs/other.go +++ b/internal/fs/other.go @@ -5,54 +5,54 @@ import ( "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/pkg/errors" ) func makeDir(ctx context.Context, path string) error { - storage, actualPath, err := operations.GetStorageAndActualPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) if err != nil { return errors.WithMessage(err, "failed get storage") } - return operations.MakeDir(ctx, storage, actualPath) + return op.MakeDir(ctx, storage, actualPath) } func move(ctx context.Context, srcPath, dstDirPath string) error { - srcStorage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath) + srcStorage, srcActualPath, err := op.GetStorageAndActualPath(srcPath) if err != nil { return errors.WithMessage(err, "failed get src storage") } - dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath) + dstStorage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) if err != nil { return errors.WithMessage(err, "failed get dst storage") } if srcStorage.GetStorage() != dstStorage.GetStorage() { return errors.WithStack(errs.MoveBetweenTwoStorages) } - return operations.Move(ctx, srcStorage, srcActualPath, dstDirActualPath) + return op.Move(ctx, srcStorage, srcActualPath, dstDirActualPath) } func rename(ctx context.Context, srcPath, dstName string) error { - storage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath) + storage, srcActualPath, err := op.GetStorageAndActualPath(srcPath) if err != nil { return errors.WithMessage(err, "failed get storage") } - return operations.Rename(ctx, storage, srcActualPath, dstName) + return op.Rename(ctx, storage, srcActualPath, dstName) } func remove(ctx context.Context, path string) error { - storage, actualPath, err := operations.GetStorageAndActualPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) if err != nil { return errors.WithMessage(err, "failed get storage") } - return operations.Remove(ctx, storage, actualPath) + return op.Remove(ctx, storage, actualPath) } func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) { - storage, actualPath, err := operations.GetStorageAndActualPath(args.Path) + storage, actualPath, err := op.GetStorageAndActualPath(args.Path) if err != nil { return nil, errors.WithMessage(err, "failed get storage") } args.Path = actualPath - return operations.Other(ctx, storage, args) + return op.Other(ctx, storage, args) } diff --git a/internal/fs/put.go b/internal/fs/put.go index 6d39e2f9..035e8cd2 100644 --- a/internal/fs/put.go +++ b/internal/fs/put.go @@ -7,7 +7,7 @@ import ( "github.com/alist-org/alist/v3/internal/errs" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/task" "github.com/alist-org/alist/v3/pkg/utils" "github.com/pkg/errors" @@ -19,7 +19,7 @@ var UploadTaskManager = task.NewTaskManager(3, func(tid *uint64) { // putAsTask add as a put task and return immediately func putAsTask(dstDirPath string, file model.FileStreamer) error { - storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath) + storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) if err != nil { return errors.WithMessage(err, "failed get storage") } @@ -36,7 +36,7 @@ func putAsTask(dstDirPath string, file model.FileStreamer) error { UploadTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{ Name: fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), storage.GetStorage().MountPath, dstDirActualPath), Func: func(task *task.Task[uint64]) error { - return operations.Put(task.Ctx, storage, dstDirActualPath, file, nil) + return op.Put(task.Ctx, storage, dstDirActualPath, file, nil) }, })) return nil @@ -44,12 +44,12 @@ func putAsTask(dstDirPath string, file model.FileStreamer) error { // putDirect put the file and return after finish func putDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer) error { - storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath) + storage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath) if err != nil { return errors.WithMessage(err, "failed get storage") } if storage.Config().NoUpload { return errors.WithStack(errs.UploadNotSupported) } - return operations.Put(ctx, storage, dstDirActualPath, file, nil) + return op.Put(ctx, storage, dstDirActualPath, file, nil) } diff --git a/internal/fs/util.go b/internal/fs/util.go index 22f0533b..10ee9e81 100644 --- a/internal/fs/util.go +++ b/internal/fs/util.go @@ -9,16 +9,16 @@ import ( "strings" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/pkg/errors" ) func ClearCache(path string) { - storage, actualPath, err := operations.GetStorageAndActualPath(path) + storage, actualPath, err := op.GetStorageAndActualPath(path) if err != nil { return } - operations.ClearCache(storage, actualPath) + op.ClearCache(storage, actualPath) } func containsByName(files []model.Obj, file model.Obj) bool { diff --git a/internal/operations/driver.go b/internal/op/driver.go similarity index 99% rename from internal/operations/driver.go rename to internal/op/driver.go index bd059b45..815aa8a9 100644 --- a/internal/operations/driver.go +++ b/internal/op/driver.go @@ -1,4 +1,4 @@ -package operations +package op import ( "reflect" diff --git a/internal/operations/driver_test.go b/internal/op/driver_test.go similarity index 67% rename from internal/operations/driver_test.go rename to internal/op/driver_test.go index 41b86ea0..1c07c9f8 100644 --- a/internal/operations/driver_test.go +++ b/internal/op/driver_test.go @@ -1,14 +1,14 @@ -package operations_test +package op_test import ( "testing" _ "github.com/alist-org/alist/v3/drivers" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" ) func TestDriverItemsMap(t *testing.T) { - itemsMap := operations.GetDriverInfoMap() + itemsMap := op.GetDriverInfoMap() if len(itemsMap) != 0 { t.Logf("driverInfoMap: %v", itemsMap) } else { diff --git a/internal/operations/fs.go b/internal/op/fs.go similarity index 98% rename from internal/operations/fs.go rename to internal/op/fs.go index 523d22ae..48066c37 100644 --- a/internal/operations/fs.go +++ b/internal/op/fs.go @@ -1,4 +1,4 @@ -package operations +package op import ( "context" @@ -17,7 +17,7 @@ import ( log "github.com/sirupsen/logrus" ) -// In order to facilitate adding some other things before and after file operations +// In order to facilitate adding some other things before and after file op var listCache = cache.NewMemCache(cache.WithShards[[]model.Obj](64)) var listG singleflight.Group[[]model.Obj] @@ -30,7 +30,7 @@ func ClearCache(storage driver.Driver, path string) { // List files in storage, not contains virtual file func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs, refresh ...bool) ([]model.Obj, error) { path = utils.StandardizePath(path) - log.Debugf("operations.List %s", path) + log.Debugf("op.List %s", path) dir, err := Get(ctx, storage, path) if err != nil { return nil, errors.WithMessage(err, "failed get dir") @@ -75,7 +75,7 @@ func isRoot(path, rootFolderPath string) bool { // Get object from list of files func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, error) { path = utils.StandardizePath(path) - log.Debugf("operations.Get %s", path) + log.Debugf("op.Get %s", path) if g, ok := storage.(driver.Getter); ok { obj, err := g.Get(ctx, path) if err == nil { diff --git a/internal/operations/path.go b/internal/op/path.go similarity index 98% rename from internal/operations/path.go rename to internal/op/path.go index d0e6d407..367c34bf 100644 --- a/internal/operations/path.go +++ b/internal/op/path.go @@ -1,4 +1,4 @@ -package operations +package op import ( stdpath "path" diff --git a/internal/operations/storage.go b/internal/op/storage.go similarity index 99% rename from internal/operations/storage.go rename to internal/op/storage.go index 7281d034..dc79112b 100644 --- a/internal/operations/storage.go +++ b/internal/op/storage.go @@ -1,4 +1,4 @@ -package operations +package op import ( "context" diff --git a/internal/operations/storage_test.go b/internal/op/storage_test.go similarity index 86% rename from internal/operations/storage_test.go rename to internal/op/storage_test.go index 2d4dbbfe..66d815dd 100644 --- a/internal/operations/storage_test.go +++ b/internal/op/storage_test.go @@ -1,4 +1,4 @@ -package operations_test +package op_test import ( "context" @@ -6,7 +6,7 @@ import ( "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/pkg/utils" "gorm.io/driver/sqlite" "gorm.io/gorm" @@ -30,7 +30,7 @@ func TestCreateStorage(t *testing.T) { {storage: model.Storage{Driver: "None", MountPath: "/none", Addition: `{"root_folder":"."}`}, isErr: true}, } for _, storage := range storages { - err := operations.CreateStorage(context.Background(), storage.storage) + err := op.CreateStorage(context.Background(), storage.storage) if err != nil { if !storage.isErr { t.Errorf("failed to create storage: %+v", err) @@ -43,7 +43,7 @@ func TestCreateStorage(t *testing.T) { func TestGetStorageVirtualFilesByPath(t *testing.T) { setupStorages(t) - virtualFiles := operations.GetStorageVirtualFilesByPath("/a") + virtualFiles := op.GetStorageVirtualFilesByPath("/a") var names []string for _, virtualFile := range virtualFiles { names = append(names, virtualFile.GetName()) @@ -58,11 +58,11 @@ func TestGetStorageVirtualFilesByPath(t *testing.T) { func TestGetBalancedStorage(t *testing.T) { setupStorages(t) - storage := operations.GetBalancedStorage("/a/d/e") + storage := op.GetBalancedStorage("/a/d/e") if storage.GetStorage().MountPath != "/a/d/e" { t.Errorf("expected: /a/d/e, got: %+v", storage.GetStorage().MountPath) } - storage = operations.GetBalancedStorage("/a/d/e") + storage = op.GetBalancedStorage("/a/d/e") if storage.GetStorage().MountPath != "/a/d/e.balance" { t.Errorf("expected: /a/d/e.balance, got: %+v", storage.GetStorage().MountPath) } @@ -77,7 +77,7 @@ func setupStorages(t *testing.T) { {Driver: "local", MountPath: "/a/d/e.balance", Index: 4, Addition: `{"root_folder":"."}`}, } for _, storage := range storages { - err := operations.CreateStorage(context.Background(), storage) + err := op.CreateStorage(context.Background(), storage) if err != nil { t.Fatalf("failed to create storage: %+v", err) } diff --git a/server/handles/driver.go b/server/handles/driver.go index 8eba4139..10c27ce8 100644 --- a/server/handles/driver.go +++ b/server/handles/driver.go @@ -3,22 +3,22 @@ package handles import ( "fmt" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" ) func ListDriverInfo(c *gin.Context) { - common.SuccessResp(c, operations.GetDriverInfoMap()) + common.SuccessResp(c, op.GetDriverInfoMap()) } func ListDriverNames(c *gin.Context) { - common.SuccessResp(c, operations.GetDriverNames()) + common.SuccessResp(c, op.GetDriverNames()) } func GetDriverInfo(c *gin.Context) { driverName := c.Query("driver") - infoMap := operations.GetDriverInfoMap() + infoMap := op.GetDriverInfoMap() items, ok := infoMap[driverName] if !ok { common.ErrorStrResp(c, fmt.Sprintf("driver [%s] not found", driverName), 404) diff --git a/server/handles/storage.go b/server/handles/storage.go index e8833b47..4d7ee0e1 100644 --- a/server/handles/storage.go +++ b/server/handles/storage.go @@ -5,7 +5,7 @@ import ( "github.com/alist-org/alist/v3/internal/db" "github.com/alist-org/alist/v3/internal/model" - "github.com/alist-org/alist/v3/internal/operations" + "github.com/alist-org/alist/v3/internal/op" "github.com/alist-org/alist/v3/server/common" "github.com/gin-gonic/gin" log "github.com/sirupsen/logrus" @@ -36,7 +36,7 @@ func CreateStorage(c *gin.Context) { common.ErrorResp(c, err, 400) return } - if err := operations.CreateStorage(c, req); err != nil { + if err := op.CreateStorage(c, req); err != nil { common.ErrorResp(c, err, 500, true) } else { common.SuccessResp(c) @@ -49,7 +49,7 @@ func UpdateStorage(c *gin.Context) { common.ErrorResp(c, err, 400) return } - if err := operations.UpdateStorage(c, req); err != nil { + if err := op.UpdateStorage(c, req); err != nil { common.ErrorResp(c, err, 500, true) } else { common.SuccessResp(c) @@ -63,7 +63,7 @@ func DeleteStorage(c *gin.Context) { common.ErrorResp(c, err, 400) return } - if err := operations.DeleteStorageById(c, uint(id)); err != nil { + if err := op.DeleteStorageById(c, uint(id)); err != nil { common.ErrorResp(c, err, 500, true) return } @@ -77,7 +77,7 @@ func DisableStorage(c *gin.Context) { common.ErrorResp(c, err, 400) return } - if err := operations.DisableStorage(c, uint(id)); err != nil { + if err := op.DisableStorage(c, uint(id)); err != nil { common.ErrorResp(c, err, 500, true) return } @@ -91,7 +91,7 @@ func EnableStorage(c *gin.Context) { common.ErrorResp(c, err, 400) return } - if err := operations.EnableStorage(c, uint(id)); err != nil { + if err := op.EnableStorage(c, uint(id)); err != nil { common.ErrorResp(c, err, 500, true) return }