2022-06-15 12:31:23 +00:00
|
|
|
package fs
|
|
|
|
|
2022-06-23 15:03:11 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2022-08-03 06:14:37 +00:00
|
|
|
|
2022-06-28 10:00:11 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/driver"
|
2022-06-23 15:03:11 +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-23 15:03:11 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-08-31 14:08:12 +00:00
|
|
|
// the param named path of functions in this package is a mount path
|
|
|
|
// So, the purpose of this package is to convert mount path to actual path
|
2022-08-31 13:01:15 +00:00
|
|
|
// then pass the actual path to the op package
|
2022-06-23 15:03:11 +00:00
|
|
|
|
2022-08-29 11:15:52 +00:00
|
|
|
func List(ctx context.Context, path string, refresh ...bool) ([]model.Obj, error) {
|
|
|
|
res, err := list(ctx, path, refresh...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed list %s: %+v", path, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Get(ctx context.Context, path string) (model.Obj, error) {
|
|
|
|
res, err := get(ctx, path)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed get %s: %+v", path, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 13:58:46 +00:00
|
|
|
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
|
|
|
res, file, err := link(ctx, path, args)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed link %s: %+v", path, err)
|
2022-06-28 13:58:46 +00:00
|
|
|
return nil, nil, err
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
2022-06-28 13:58:46 +00:00
|
|
|
return res, file, nil
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func MakeDir(ctx context.Context, path string, lazyCache ...bool) error {
|
|
|
|
err := makeDir(ctx, path, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed make dir %s: %+v", path, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func Move(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) error {
|
|
|
|
err := move(ctx, srcPath, dstDirPath, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed move %s to %s: %+v", srcPath, dstDirPath, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func Copy(ctx context.Context, srcObjPath, dstDirPath string, lazyCache ...bool) (bool, error) {
|
|
|
|
res, err := _copy(ctx, srcObjPath, dstDirPath, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed copy %s to %s: %+v", srcObjPath, dstDirPath, err)
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func Rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error {
|
|
|
|
err := rename(ctx, srcPath, dstName, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed rename %s to %s: %+v", srcPath, dstName, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func Remove(ctx context.Context, path string) error {
|
|
|
|
err := remove(ctx, path)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed remove %s: %+v", path, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func PutDirectly(ctx context.Context, dstDirPath string, file *model.FileStream, lazyCache ...bool) error {
|
|
|
|
err := putDirectly(ctx, dstDirPath, file, lazyCache...)
|
2022-06-24 06:21:28 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed put %s: %+v", dstDirPath, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-17 11:49:05 +00:00
|
|
|
func PutAsTask(dstDirPath string, file *model.FileStream) error {
|
2022-06-24 06:21:28 +00:00
|
|
|
err := putAsTask(dstDirPath, file)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed put %s: %+v", dstDirPath, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2022-06-28 10:00:11 +00:00
|
|
|
|
2022-07-10 06:45:39 +00:00
|
|
|
func GetStorage(path string) (driver.Driver, error) {
|
2022-08-31 13:01:15 +00:00
|
|
|
storageDriver, _, err := op.GetStorageAndActualPath(path)
|
2022-06-28 10:00:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-10 06:45:39 +00:00
|
|
|
return storageDriver, nil
|
2022-06-28 10:00:11 +00:00
|
|
|
}
|
2022-08-03 06:14:37 +00:00
|
|
|
|
|
|
|
func Other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
|
|
|
res, err := other(ctx, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed remove %s: %+v", args.Path, err)
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|