chore: rename account to storage
This commit is contained in:
@ -19,40 +19,40 @@ var CopyTaskManager = task.NewTaskManager(3, func(tid *uint64) {
|
||||
atomic.AddUint64(tid, 1)
|
||||
})
|
||||
|
||||
// Copy if in an account, call move method
|
||||
// Copy if in the same storage, call move method
|
||||
// if not, add copy task
|
||||
func _copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) {
|
||||
srcAccount, srcObjActualPath, err := operations.GetAccountAndActualPath(srcObjPath)
|
||||
srcStorage, srcObjActualPath, err := operations.GetStorageAndActualPath(srcObjPath)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "failed get src account")
|
||||
return false, errors.WithMessage(err, "failed get src storage")
|
||||
}
|
||||
dstAccount, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
||||
if err != nil {
|
||||
return false, errors.WithMessage(err, "failed get dst account")
|
||||
return false, errors.WithMessage(err, "failed get dst storage")
|
||||
}
|
||||
// copy if in an account, just call driver.Copy
|
||||
if srcAccount.GetAccount() == dstAccount.GetAccount() {
|
||||
return false, operations.Copy(ctx, srcAccount, srcObjActualPath, dstDirActualPath)
|
||||
// copy if in the same storage, just call driver.Copy
|
||||
if srcStorage.GetStorage() == dstStorage.GetStorage() {
|
||||
return false, operations.Copy(ctx, srcStorage, srcObjActualPath, dstDirActualPath)
|
||||
}
|
||||
// not in an account
|
||||
// not in the same storage
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjActualPath, dstAccount.GetAccount().VirtualPath, dstDirActualPath),
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcStorage.GetStorage().VirtualPath, srcObjActualPath, dstStorage.GetStorage().VirtualPath, dstDirActualPath),
|
||||
Func: func(task *task.Task[uint64]) error {
|
||||
return copyBetween2Accounts(task, srcAccount, dstAccount, srcObjActualPath, dstDirActualPath)
|
||||
return copyBetween2Storages(task, srcStorage, dstStorage, srcObjActualPath, dstDirActualPath)
|
||||
},
|
||||
}))
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func copyBetween2Accounts(t *task.Task[uint64], srcAccount, dstAccount driver.Driver, srcObjPath, dstDirPath string) 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, srcAccount, srcObjPath)
|
||||
srcObj, err := operations.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, srcAccount, srcObjPath)
|
||||
objs, err := operations.List(t.Ctx, srcStorage, srcObjPath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed list src [%s] objs", srcObjPath)
|
||||
}
|
||||
@ -63,29 +63,29 @@ func copyBetween2Accounts(t *task.Task[uint64], srcAccount, dstAccount driver.Dr
|
||||
srcObjPath := stdpath.Join(srcObjPath, obj.GetName())
|
||||
dstObjPath := stdpath.Join(dstDirPath, obj.GetName())
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjPath, dstAccount.GetAccount().VirtualPath, dstObjPath),
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcStorage.GetStorage().VirtualPath, srcObjPath, dstStorage.GetStorage().VirtualPath, dstObjPath),
|
||||
Func: func(t *task.Task[uint64]) error {
|
||||
return copyBetween2Accounts(t, srcAccount, dstAccount, srcObjPath, dstObjPath)
|
||||
return copyBetween2Storages(t, srcStorage, dstStorage, srcObjPath, dstObjPath)
|
||||
},
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
CopyTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcAccount.GetAccount().VirtualPath, srcObjPath, dstAccount.GetAccount().VirtualPath, dstDirPath),
|
||||
Name: fmt.Sprintf("copy [%s](%s) to [%s](%s)", srcStorage.GetStorage().VirtualPath, srcObjPath, dstStorage.GetStorage().VirtualPath, dstDirPath),
|
||||
Func: func(t *task.Task[uint64]) error {
|
||||
return copyFileBetween2Accounts(t, srcAccount, dstAccount, srcObjPath, dstDirPath)
|
||||
return copyFileBetween2Storages(t, srcStorage, dstStorage, srcObjPath, dstDirPath)
|
||||
},
|
||||
}))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyFileBetween2Accounts(tsk *task.Task[uint64], srcAccount, dstAccount driver.Driver, srcFilePath, dstDirPath string) error {
|
||||
srcFile, err := operations.Get(tsk.Ctx, srcAccount, srcFilePath)
|
||||
func copyFileBetween2Storages(tsk *task.Task[uint64], srcStorage, dstStorage driver.Driver, srcFilePath, dstDirPath string) error {
|
||||
srcFile, err := operations.Get(tsk.Ctx, srcStorage, srcFilePath)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get src [%s] file", srcFilePath)
|
||||
}
|
||||
link, _, err := operations.Link(tsk.Ctx, srcAccount, srcFilePath, model.LinkArgs{})
|
||||
link, _, err := operations.Link(tsk.Ctx, srcStorage, srcFilePath, model.LinkArgs{})
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get [%s] link", srcFilePath)
|
||||
}
|
||||
@ -93,5 +93,5 @@ func copyFileBetween2Accounts(tsk *task.Task[uint64], srcAccount, dstAccount dri
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "failed get [%s] stream", srcFilePath)
|
||||
}
|
||||
return operations.Put(tsk.Ctx, dstAccount, dstDirPath, stream, tsk.SetProgress)
|
||||
return operations.Put(tsk.Ctx, dstStorage, dstDirPath, stream, tsk.SetProgress)
|
||||
}
|
||||
|
@ -95,10 +95,10 @@ func PutAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetAccount(path string) (driver.Driver, error) {
|
||||
accountDriver, _, err := operations.GetAccountAndActualPath(path)
|
||||
func GetStorage(path string) (driver.Driver, error) {
|
||||
storageDriver, _, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return accountDriver, nil
|
||||
return storageDriver, nil
|
||||
}
|
||||
|
@ -14,16 +14,16 @@ func get(ctx context.Context, path string) (model.Obj, error) {
|
||||
path = utils.StandardizePath(path)
|
||||
// maybe a virtual file
|
||||
if path != "/" {
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath(stdpath.Dir(path))
|
||||
virtualFiles := operations.GetStorageVirtualFilesByPath(stdpath.Dir(path))
|
||||
for _, f := range virtualFiles {
|
||||
if f.GetName() == stdpath.Base(path) {
|
||||
return f, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
// if there are no account prefix with path, maybe root folder
|
||||
// if there are no storage prefix with path, maybe root folder
|
||||
if path == "/" {
|
||||
return model.Object{
|
||||
Name: "root",
|
||||
@ -32,7 +32,7 @@ func get(ctx context.Context, path string) (model.Obj, error) {
|
||||
IsFolder: true,
|
||||
}, nil
|
||||
}
|
||||
return nil, errors.WithMessage(err, "failed get account")
|
||||
return nil, errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.Get(ctx, account, actualPath)
|
||||
return operations.Get(ctx, storage, actualPath)
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithMessage(err, "failed get account")
|
||||
return nil, nil, errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.Link(ctx, account, actualPath, args)
|
||||
return operations.Link(ctx, storage, actualPath, args)
|
||||
}
|
||||
|
@ -15,15 +15,15 @@ import (
|
||||
func list(ctx context.Context, path string) ([]model.Obj, error) {
|
||||
meta := ctx.Value("meta").(*model.Meta)
|
||||
user := ctx.Value("user").(*model.User)
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
virtualFiles := operations.GetAccountVirtualFilesByPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
virtualFiles := operations.GetStorageVirtualFilesByPath(path)
|
||||
if err != nil {
|
||||
if len(virtualFiles) != 0 {
|
||||
return virtualFiles, nil
|
||||
}
|
||||
return nil, errors.WithMessage(err, "failed get account")
|
||||
return nil, errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
objs, err := operations.List(ctx, account, actualPath)
|
||||
objs, err := operations.List(ctx, storage, actualPath)
|
||||
if err != nil {
|
||||
log.Errorf("%+v", err)
|
||||
if len(virtualFiles) != 0 {
|
||||
@ -31,19 +31,19 @@ func list(ctx context.Context, path string) ([]model.Obj, error) {
|
||||
}
|
||||
return nil, errors.WithMessage(err, "failed get objs")
|
||||
}
|
||||
for _, accountFile := range virtualFiles {
|
||||
if !containsByName(objs, accountFile) {
|
||||
objs = append(objs, accountFile)
|
||||
for _, storageFile := range virtualFiles {
|
||||
if !containsByName(objs, storageFile) {
|
||||
objs = append(objs, storageFile)
|
||||
}
|
||||
}
|
||||
if whetherHide(user, meta, path) {
|
||||
objs = hide(objs, meta)
|
||||
}
|
||||
// sort objs
|
||||
if account.Config().LocalSort {
|
||||
model.SortFiles(objs, account.GetAccount().OrderBy, account.GetAccount().OrderDirection)
|
||||
if storage.Config().LocalSort {
|
||||
model.SortFiles(objs, storage.GetStorage().OrderBy, storage.GetStorage().OrderDirection)
|
||||
}
|
||||
model.ExtractFolder(objs, account.GetAccount().ExtractFolder)
|
||||
model.ExtractFolder(objs, storage.GetStorage().ExtractFolder)
|
||||
return objs, nil
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,12 @@ var UploadTaskManager = task.NewTaskManager[uint64](3, func(tid *uint64) {
|
||||
|
||||
// putAsTask add as a put task and return immediately
|
||||
func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||
account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
if account.Config().NoUpload {
|
||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
||||
if storage.Config().NoUpload {
|
||||
return errors.WithStack(errs.UploadNotSupported)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
return errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
if file.NeedStore() {
|
||||
tempFile, err := utils.CreateTempFile(file)
|
||||
@ -33,9 +33,9 @@ func putAsTask(dstDirPath string, file model.FileStreamer) error {
|
||||
file.SetReadCloser(tempFile)
|
||||
}
|
||||
UploadTaskManager.Submit(task.WithCancelCtx(&task.Task[uint64]{
|
||||
Name: fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), account.GetAccount().VirtualPath, dstDirActualPath),
|
||||
Name: fmt.Sprintf("upload %s to [%s](%s)", file.GetName(), storage.GetStorage().VirtualPath, dstDirActualPath),
|
||||
Func: func(task *task.Task[uint64]) error {
|
||||
return operations.Put(task.Ctx, account, dstDirActualPath, file, nil)
|
||||
return operations.Put(task.Ctx, storage, dstDirActualPath, file, nil)
|
||||
},
|
||||
}))
|
||||
return nil
|
||||
@ -43,12 +43,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 {
|
||||
account, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
if account.Config().NoUpload {
|
||||
storage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
||||
if storage.Config().NoUpload {
|
||||
return errors.WithStack(errs.UploadNotSupported)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
return errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.Put(ctx, account, dstDirActualPath, file, nil)
|
||||
return operations.Put(ctx, storage, dstDirActualPath, file, nil)
|
||||
}
|
||||
|
@ -14,11 +14,11 @@ import (
|
||||
)
|
||||
|
||||
func ClearCache(path string) {
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
operations.ClearCache(account, actualPath)
|
||||
operations.ClearCache(storage, actualPath)
|
||||
}
|
||||
|
||||
func containsByName(files []model.Obj, file model.Obj) bool {
|
||||
|
@ -8,40 +8,40 @@ import (
|
||||
)
|
||||
|
||||
func makeDir(ctx context.Context, path string) error {
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
return errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.MakeDir(ctx, account, actualPath)
|
||||
return operations.MakeDir(ctx, storage, actualPath)
|
||||
}
|
||||
|
||||
func move(ctx context.Context, srcPath, dstDirPath string) error {
|
||||
srcAccount, srcActualPath, err := operations.GetAccountAndActualPath(srcPath)
|
||||
srcStorage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get src account")
|
||||
return errors.WithMessage(err, "failed get src storage")
|
||||
}
|
||||
dstAccount, dstDirActualPath, err := operations.GetAccountAndActualPath(dstDirPath)
|
||||
dstStorage, dstDirActualPath, err := operations.GetStorageAndActualPath(dstDirPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get dst account")
|
||||
return errors.WithMessage(err, "failed get dst storage")
|
||||
}
|
||||
if srcAccount.GetAccount() != dstAccount.GetAccount() {
|
||||
return errors.WithStack(errs.MoveBetweenTwoAccounts)
|
||||
if srcStorage.GetStorage() != dstStorage.GetStorage() {
|
||||
return errors.WithStack(errs.MoveBetweenTwoStorages)
|
||||
}
|
||||
return operations.Move(ctx, srcAccount, srcActualPath, dstDirActualPath)
|
||||
return operations.Move(ctx, srcStorage, srcActualPath, dstDirActualPath)
|
||||
}
|
||||
|
||||
func rename(ctx context.Context, srcPath, dstName string) error {
|
||||
account, srcActualPath, err := operations.GetAccountAndActualPath(srcPath)
|
||||
storage, srcActualPath, err := operations.GetStorageAndActualPath(srcPath)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
return errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.Rename(ctx, account, srcActualPath, dstName)
|
||||
return operations.Rename(ctx, storage, srcActualPath, dstName)
|
||||
}
|
||||
|
||||
func remove(ctx context.Context, path string) error {
|
||||
account, actualPath, err := operations.GetAccountAndActualPath(path)
|
||||
storage, actualPath, err := operations.GetStorageAndActualPath(path)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "failed get account")
|
||||
return errors.WithMessage(err, "failed get storage")
|
||||
}
|
||||
return operations.Remove(ctx, account, actualPath)
|
||||
return operations.Remove(ctx, storage, actualPath)
|
||||
}
|
||||
|
Reference in New Issue
Block a user