MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / list

Function list

internal/sharing/list.go:14–83  ·  view source on GitHub ↗
(ctx context.Context, sid, path string, args model.SharingListArgs)

Source from the content-addressed store, hash-verified

12)
13
14func list(ctx context.Context, sid, path string, args model.SharingListArgs) (*model.Sharing, []model.Obj, error) {
15 sharing, err := op.GetSharingById(sid, args.Refresh)
16 if err != nil {
17 return nil, nil, errors.WithStack(errs.SharingNotFound)
18 }
19 if !sharing.Valid() {
20 return sharing, nil, errors.WithStack(errs.InvalidSharing)
21 }
22 if !sharing.Verify(args.Pwd) {
23 return sharing, nil, errors.WithStack(errs.WrongShareCode)
24 }
25 path = utils.FixAndCleanPath(path)
26 if len(sharing.Files) == 1 || path != "/" {
27 unwrapPath, err := op.GetSharingUnwrapPath(sharing, path)
28 if err != nil {
29 return nil, nil, errors.WithMessage(err, "failed get sharing unwrap path")
30 }
31 virtualFiles := op.GetStorageVirtualFilesByPath(unwrapPath)
32 storage, actualPath, err := op.GetStorageAndActualPath(unwrapPath)
33 if err != nil && len(virtualFiles) == 0 {
34 return nil, nil, errors.WithMessage(err, "failed list sharing")
35 }
36 var objs []model.Obj
37 if storage != nil {
38 objs, err = op.List(ctx, storage, actualPath, model.ListArgs{
39 Refresh: args.Refresh,
40 ReqPath: stdpath.Join(sid, path),
41 })
42 if err != nil && len(virtualFiles) == 0 {
43 return nil, nil, errors.WithMessage(err, "failed list sharing")
44 }
45 }
46 om := model.NewObjMerge()
47 objs = om.Merge(objs, virtualFiles...)
48 model.SortFiles(objs, sharing.OrderBy, sharing.OrderDirection)
49 model.ExtractFolder(objs, sharing.ExtractFolder)
50 return sharing, objs, nil
51 }
52 objs := make([]model.Obj, 0, len(sharing.Files))
53 for _, f := range sharing.Files {
54 if f != "/" {
55 isVf := false
56 virtualFiles := op.GetStorageVirtualFilesByPath(stdpath.Dir(f))
57 for _, vf := range virtualFiles {
58 if vf.GetName() == stdpath.Base(f) {
59 objs = append(objs, vf)
60 isVf = true
61 break
62 }
63 }
64 if isVf {
65 continue
66 }
67 } else {
68 continue
69 }
70 storage, actualPath, err := op.GetStorageAndActualPath(f)
71 if err != nil {

Callers 1

ListFunction · 0.70

Calls 14

MergeMethod · 0.95
GetSharingByIdFunction · 0.92
FixAndCleanPathFunction · 0.92
GetSharingUnwrapPathFunction · 0.92
GetStorageAndActualPathFunction · 0.92
ListFunction · 0.92
NewObjMergeFunction · 0.92
SortFilesFunction · 0.92
ExtractFolderFunction · 0.92
GetFunction · 0.92
ValidMethod · 0.80

Tested by

no test coverage detected