Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/fs/fs.go
1560 views
1
package fs
2
3
import (
4
"context"
5
log "github.com/sirupsen/logrus"
6
"io"
7
8
"github.com/alist-org/alist/v3/internal/driver"
9
"github.com/alist-org/alist/v3/internal/errs"
10
"github.com/alist-org/alist/v3/internal/model"
11
"github.com/alist-org/alist/v3/internal/op"
12
"github.com/alist-org/alist/v3/internal/task"
13
"github.com/pkg/errors"
14
)
15
16
// the param named path of functions in this package is a mount path
17
// So, the purpose of this package is to convert mount path to actual path
18
// then pass the actual path to the op package
19
20
type ListArgs struct {
21
Refresh bool
22
NoLog bool
23
}
24
25
func List(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {
26
res, err := list(ctx, path, args)
27
if err != nil {
28
if !args.NoLog {
29
log.Errorf("failed list %s: %+v", path, err)
30
}
31
return nil, err
32
}
33
return res, nil
34
}
35
36
type GetArgs struct {
37
NoLog bool
38
}
39
40
func Get(ctx context.Context, path string, args *GetArgs) (model.Obj, error) {
41
res, err := get(ctx, path)
42
if err != nil {
43
if !args.NoLog {
44
log.Warnf("failed get %s: %s", path, err)
45
}
46
return nil, err
47
}
48
return res, nil
49
}
50
51
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
52
res, file, err := link(ctx, path, args)
53
if err != nil {
54
log.Errorf("failed link %s: %+v", path, err)
55
return nil, nil, err
56
}
57
return res, file, nil
58
}
59
60
func MakeDir(ctx context.Context, path string, lazyCache ...bool) error {
61
err := makeDir(ctx, path, lazyCache...)
62
if err != nil {
63
log.Errorf("failed make dir %s: %+v", path, err)
64
}
65
return err
66
}
67
68
func Move(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) error {
69
err := move(ctx, srcPath, dstDirPath, lazyCache...)
70
if err != nil {
71
log.Errorf("failed move %s to %s: %+v", srcPath, dstDirPath, err)
72
}
73
return err
74
}
75
76
func Copy(ctx context.Context, srcObjPath, dstDirPath string, lazyCache ...bool) (task.TaskExtensionInfo, error) {
77
res, err := _copy(ctx, srcObjPath, dstDirPath, lazyCache...)
78
if err != nil {
79
log.Errorf("failed copy %s to %s: %+v", srcObjPath, dstDirPath, err)
80
}
81
return res, err
82
}
83
84
func Rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error {
85
err := rename(ctx, srcPath, dstName, lazyCache...)
86
if err != nil {
87
log.Errorf("failed rename %s to %s: %+v", srcPath, dstName, err)
88
}
89
return err
90
}
91
92
func Remove(ctx context.Context, path string) error {
93
err := remove(ctx, path)
94
if err != nil {
95
log.Errorf("failed remove %s: %+v", path, err)
96
}
97
return err
98
}
99
100
func PutDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer, lazyCache ...bool) error {
101
err := putDirectly(ctx, dstDirPath, file, lazyCache...)
102
if err != nil {
103
log.Errorf("failed put %s: %+v", dstDirPath, err)
104
}
105
return err
106
}
107
108
func PutAsTask(ctx context.Context, dstDirPath string, file model.FileStreamer) (task.TaskExtensionInfo, error) {
109
t, err := putAsTask(ctx, dstDirPath, file)
110
if err != nil {
111
log.Errorf("failed put %s: %+v", dstDirPath, err)
112
}
113
return t, err
114
}
115
116
func ArchiveMeta(ctx context.Context, path string, args model.ArchiveMetaArgs) (*model.ArchiveMetaProvider, error) {
117
meta, err := archiveMeta(ctx, path, args)
118
if err != nil {
119
log.Errorf("failed get archive meta %s: %+v", path, err)
120
}
121
return meta, err
122
}
123
124
func ArchiveList(ctx context.Context, path string, args model.ArchiveListArgs) ([]model.Obj, error) {
125
objs, err := archiveList(ctx, path, args)
126
if err != nil {
127
log.Errorf("failed list archive [%s]%s: %+v", path, args.InnerPath, err)
128
}
129
return objs, err
130
}
131
132
func ArchiveDecompress(ctx context.Context, srcObjPath, dstDirPath string, args model.ArchiveDecompressArgs, lazyCache ...bool) (task.TaskExtensionInfo, error) {
133
t, err := archiveDecompress(ctx, srcObjPath, dstDirPath, args, lazyCache...)
134
if err != nil {
135
log.Errorf("failed decompress [%s]%s: %+v", srcObjPath, args.InnerPath, err)
136
}
137
return t, err
138
}
139
140
func ArchiveDriverExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (*model.Link, model.Obj, error) {
141
l, obj, err := archiveDriverExtract(ctx, path, args)
142
if err != nil {
143
log.Errorf("failed extract [%s]%s: %+v", path, args.InnerPath, err)
144
}
145
return l, obj, err
146
}
147
148
func ArchiveInternalExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (io.ReadCloser, int64, error) {
149
l, obj, err := archiveInternalExtract(ctx, path, args)
150
if err != nil {
151
log.Errorf("failed extract [%s]%s: %+v", path, args.InnerPath, err)
152
}
153
return l, obj, err
154
}
155
156
type GetStoragesArgs struct {
157
}
158
159
func GetStorage(path string, args *GetStoragesArgs) (driver.Driver, error) {
160
storageDriver, _, err := op.GetStorageAndActualPath(path)
161
if err != nil {
162
return nil, err
163
}
164
return storageDriver, nil
165
}
166
167
func Other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
168
res, err := other(ctx, args)
169
if err != nil {
170
log.Errorf("failed remove %s: %+v", args.Path, err)
171
}
172
return res, err
173
}
174
175
func PutURL(ctx context.Context, path, dstName, urlStr string) error {
176
storage, dstDirActualPath, err := op.GetStorageAndActualPath(path)
177
if err != nil {
178
return errors.WithMessage(err, "failed get storage")
179
}
180
if storage.Config().NoUpload {
181
return errors.WithStack(errs.UploadNotSupported)
182
}
183
_, ok := storage.(driver.PutURL)
184
_, okResult := storage.(driver.PutURLResult)
185
if !ok && !okResult {
186
return errs.NotImplement
187
}
188
return op.PutURL(ctx, storage, dstDirActualPath, dstName, urlStr)
189
}
190
191