style: shorten name operations
to op
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user