2022-06-10 13:00:51 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-03 06:14:37 +00:00
|
|
|
|
2022-06-23 07:57:10 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/errs"
|
2022-08-03 06:14:37 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-08-31 13:01:15 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2022-06-10 13:00:51 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func makeDir(ctx context.Context, path string, lazyCache ...bool) error {
|
2022-08-31 13:01:15 +00:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
2022-06-10 13:00:51 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-12-20 07:02:40 +00:00
|
|
|
return op.MakeDir(ctx, storage, actualPath, lazyCache...)
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func move(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) error {
|
2022-08-31 13:01:15 +00:00
|
|
|
srcStorage, srcActualPath, err := op.GetStorageAndActualPath(srcPath)
|
2022-06-10 13:00:51 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return errors.WithMessage(err, "failed get src storage")
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-08-31 13:01:15 +00:00
|
|
|
dstStorage, dstDirActualPath, err := op.GetStorageAndActualPath(dstDirPath)
|
2022-06-10 13:00:51 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return errors.WithMessage(err, "failed get dst storage")
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-07-10 06:45:39 +00:00
|
|
|
if srcStorage.GetStorage() != dstStorage.GetStorage() {
|
|
|
|
return errors.WithStack(errs.MoveBetweenTwoStorages)
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-12-20 07:02:40 +00:00
|
|
|
return op.Move(ctx, srcStorage, srcActualPath, dstDirActualPath, lazyCache...)
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error {
|
2022-08-31 13:01:15 +00:00
|
|
|
storage, srcActualPath, err := op.GetStorageAndActualPath(srcPath)
|
2022-06-10 13:00:51 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-12-20 07:02:40 +00:00
|
|
|
return op.Rename(ctx, storage, srcActualPath, dstName, lazyCache...)
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
|
|
|
|
2022-06-23 15:03:11 +00:00
|
|
|
func remove(ctx context.Context, path string) error {
|
2022-08-31 13:01:15 +00:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
2022-06-10 13:00:51 +00:00
|
|
|
if err != nil {
|
2022-07-10 06:45:39 +00:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-08-31 13:01:15 +00:00
|
|
|
return op.Remove(ctx, storage, actualPath)
|
2022-06-10 13:00:51 +00:00
|
|
|
}
|
2022-08-03 06:14:37 +00:00
|
|
|
|
|
|
|
func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
2022-08-31 13:01:15 +00:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(args.Path)
|
2022-08-03 06:14:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithMessage(err, "failed get storage")
|
|
|
|
}
|
|
|
|
args.Path = actualPath
|
2022-08-31 13:01:15 +00:00
|
|
|
return op.Other(ctx, storage, args)
|
2022-08-03 06:14:37 +00:00
|
|
|
}
|