-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: extract fs func and add error log
- Loading branch information
Showing
9 changed files
with
185 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,86 @@ | ||
package fs | ||
|
||
import ( | ||
"context" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
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 | ||
|
||
func List(ctx context.Context, path string) ([]model.Obj, error) { | ||
res, err := list(ctx, path) | ||
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 | ||
} | ||
|
||
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, error) { | ||
res, err := link(ctx, path, args) | ||
if err != nil { | ||
log.Errorf("failed link %s: %+v", path, err) | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
func MakeDir(ctx context.Context, path string) error { | ||
err := makeDir(ctx, path) | ||
if err != nil { | ||
log.Errorf("failed make dir %s: %+v", path, err) | ||
} | ||
return err | ||
} | ||
|
||
func Move(ctx context.Context, srcPath, dstDirPath string) error { | ||
err := move(ctx, srcPath, dstDirPath) | ||
if err != nil { | ||
log.Errorf("failed move %s to %s: %+v", srcPath, dstDirPath, err) | ||
} | ||
return err | ||
} | ||
|
||
func Copy(ctx context.Context, srcObjPath, dstDirPath string) (bool, error) { | ||
res, err := _copy(ctx, srcObjPath, dstDirPath) | ||
if err != nil { | ||
log.Errorf("failed copy %s to %s: %+v", srcObjPath, dstDirPath, err) | ||
} | ||
return res, err | ||
} | ||
|
||
func Rename(ctx context.Context, srcPath, dstName string) error { | ||
err := rename(ctx, srcPath, dstName) | ||
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 | ||
} | ||
|
||
func Put(ctx context.Context, dstDirPath string, file model.FileStreamer) error { | ||
err := put(ctx, dstDirPath, file) | ||
if err != nil { | ||
log.Errorf("failed put %s: %+v", dstDirPath, err) | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fs | ||
|
||
import ( | ||
"context" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/alist-org/alist/v3/internal/operations" | ||
"github.com/alist-org/alist/v3/pkg/utils" | ||
"github.com/pkg/errors" | ||
stdpath "path" | ||
"time" | ||
) | ||
|
||
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)) | ||
for _, f := range virtualFiles { | ||
if f.GetName() == stdpath.Base(path) { | ||
return f, nil | ||
} | ||
} | ||
} | ||
account, actualPath, err := operations.GetAccountAndActualPath(path) | ||
if err != nil { | ||
// if there are no account prefix with path, maybe root folder | ||
if path == "/" { | ||
return model.Object{ | ||
Name: "root", | ||
Size: 0, | ||
Modified: time.Time{}, | ||
IsFolder: true, | ||
}, nil | ||
} | ||
return nil, errors.WithMessage(err, "failed get account") | ||
} | ||
return operations.Get(ctx, account, actualPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package fs | ||
|
||
import ( | ||
"context" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/alist-org/alist/v3/internal/operations" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, error) { | ||
account, actualPath, err := operations.GetAccountAndActualPath(path) | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "failed get account") | ||
} | ||
return operations.Link(ctx, account, actualPath, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fs | ||
|
||
import ( | ||
"context" | ||
"github.com/alist-org/alist/v3/internal/model" | ||
"github.com/alist-org/alist/v3/internal/operations" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// List files | ||
// TODO: hide | ||
// TODO: sort | ||
func list(ctx context.Context, path string) ([]model.Obj, error) { | ||
account, actualPath, err := operations.GetAccountAndActualPath(path) | ||
virtualFiles := operations.GetAccountVirtualFilesByPath(path) | ||
if err != nil { | ||
if len(virtualFiles) != 0 { | ||
return virtualFiles, nil | ||
} | ||
return nil, errors.WithMessage(err, "failed get account") | ||
} | ||
files, err := operations.List(ctx, account, actualPath) | ||
if err != nil { | ||
log.Errorf("%+v", err) | ||
if len(virtualFiles) != 0 { | ||
return virtualFiles, nil | ||
} | ||
return nil, errors.WithMessage(err, "failed get files") | ||
} | ||
for _, accountFile := range virtualFiles { | ||
if !containsByName(files, accountFile) { | ||
files = append(files, accountFile) | ||
} | ||
} | ||
return files, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters