Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/fs/get.go
1560 views
1
package fs
2
3
import (
4
"context"
5
stdpath "path"
6
"time"
7
8
"github.com/alist-org/alist/v3/internal/model"
9
"github.com/alist-org/alist/v3/internal/op"
10
"github.com/alist-org/alist/v3/pkg/utils"
11
"github.com/pkg/errors"
12
)
13
14
func get(ctx context.Context, path string) (model.Obj, error) {
15
path = utils.FixAndCleanPath(path)
16
// maybe a virtual file
17
if path != "/" {
18
virtualFiles := op.GetStorageVirtualFilesByPath(stdpath.Dir(path))
19
for _, f := range virtualFiles {
20
if f.GetName() == stdpath.Base(path) {
21
return f, nil
22
}
23
}
24
}
25
storage, actualPath, err := op.GetStorageAndActualPath(path)
26
if err != nil {
27
// if there are no storage prefix with path, maybe root folder
28
if path == "/" {
29
return &model.Object{
30
Name: "root",
31
Size: 0,
32
Modified: time.Time{},
33
IsFolder: true,
34
}, nil
35
}
36
return nil, errors.WithMessage(err, "failed get storage")
37
}
38
return op.Get(ctx, storage, actualPath)
39
}
40
41