2022-06-10 21:00:51 +08:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-03 14:14:37 +08:00
|
|
|
|
2025-07-24 16:15:24 +08:00
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/driver"
|
2025-07-01 09:54:50 +08:00
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/op"
|
2025-07-24 16:15:24 +08:00
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/task"
|
2022-06-10 21:00:51 +08:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2022-12-20 15:02:40 +08:00
|
|
|
func makeDir(ctx context.Context, path string, lazyCache ...bool) error {
|
2022-08-31 21:01:15 +08:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
2022-06-10 21:00:51 +08:00
|
|
|
if err != nil {
|
2022-07-10 14:45:39 +08:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
2022-12-20 15:02:40 +08:00
|
|
|
return op.MakeDir(ctx, storage, actualPath, lazyCache...)
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
|
|
|
|
2022-12-20 15:02:40 +08:00
|
|
|
func rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error {
|
2022-08-31 21:01:15 +08:00
|
|
|
storage, srcActualPath, err := op.GetStorageAndActualPath(srcPath)
|
2022-06-10 21:00:51 +08:00
|
|
|
if err != nil {
|
2022-07-10 14:45:39 +08:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
2022-12-20 15:02:40 +08:00
|
|
|
return op.Rename(ctx, storage, srcActualPath, dstName, lazyCache...)
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
|
|
|
|
2022-06-23 23:03:11 +08:00
|
|
|
func remove(ctx context.Context, path string) error {
|
2022-08-31 21:01:15 +08:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(path)
|
2022-06-10 21:00:51 +08:00
|
|
|
if err != nil {
|
2022-07-10 14:45:39 +08:00
|
|
|
return errors.WithMessage(err, "failed get storage")
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
2022-08-31 21:01:15 +08:00
|
|
|
return op.Remove(ctx, storage, actualPath)
|
2022-06-10 21:00:51 +08:00
|
|
|
}
|
2022-08-03 14:14:37 +08:00
|
|
|
|
|
|
|
func other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
2022-08-31 21:01:15 +08:00
|
|
|
storage, actualPath, err := op.GetStorageAndActualPath(args.Path)
|
2022-08-03 14:14:37 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.WithMessage(err, "failed get storage")
|
|
|
|
}
|
|
|
|
args.Path = actualPath
|
2022-08-31 21:01:15 +08:00
|
|
|
return op.Other(ctx, storage, args)
|
2022-08-03 14:14:37 +08:00
|
|
|
}
|
2025-07-24 16:15:24 +08:00
|
|
|
|
|
|
|
type TaskData struct {
|
|
|
|
task.TaskExtension
|
|
|
|
Status string `json:"-"` //don't save status to save space
|
|
|
|
SrcActualPath string `json:"src_path"`
|
|
|
|
DstActualPath string `json:"dst_path"`
|
|
|
|
SrcStorage driver.Driver `json:"-"`
|
|
|
|
DstStorage driver.Driver `json:"-"`
|
|
|
|
SrcStorageMp string `json:"src_storage_mp"`
|
|
|
|
DstStorageMp string `json:"dst_storage_mp"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TaskData) GetStatus() string {
|
|
|
|
return t.Status
|
|
|
|
}
|