MCPcopy
hub / github.com/rclone/rclone / NewFs

Function NewFs

backend/filelu/filelu.go:111–168  ·  view source on GitHub ↗

NewFs creates a new Fs object for FileLu

(ctx context.Context, name string, root string, m configmap.Mapper)

Source from the content-addressed store, hash-verified

109
110// NewFs creates a new Fs object for FileLu
111func NewFs(ctx context.Context, name string, root string, m configmap.Mapper) (fs.Fs, error) {
112 opt := new(Options)
113 err := configstruct.Set(m, opt)
114 if err != nil {
115 return nil, fmt.Errorf("failed to parse config: %w", err)
116 }
117
118 if opt.Key == "" {
119 return nil, fmt.Errorf("FileLu Rclone Key is required")
120 }
121
122 client := fshttp.NewClient(ctx)
123
124 if strings.TrimSpace(root) == "" {
125 root = ""
126 }
127 root = strings.Trim(root, "/")
128
129 filename := ""
130
131 f := &Fs{
132 name: name,
133 opt: *opt,
134 endpoint: "https://filelu.com/rclone",
135 client: client,
136 srv: rest.NewClient(client).SetRoot("https://filelu.com/rclone"),
137 pacer: pacer.New(),
138 targetFile: filename,
139 root: root,
140 }
141
142 f.features = (&fs.Features{
143 CanHaveEmptyDirectories: true,
144 WriteMetadata: false,
145 SlowHash: true,
146 }).Fill(ctx, f)
147
148 rootContainer, rootDirectory := rootSplit(f.root)
149 if rootContainer != "" && rootDirectory != "" {
150 // Check to see if the (container,directory) is actually an existing file
151 oldRoot := f.root
152 newRoot, leaf := path.Split(oldRoot)
153 f.root = strings.Trim(newRoot, "/")
154 _, err := f.NewObject(ctx, leaf)
155 if err != nil {
156 if err == fs.ErrorObjectNotFound || err == fs.ErrorNotAFile {
157 // File doesn't exist or is a directory so return old f
158 f.root = strings.Trim(oldRoot, "/")
159 return f, nil
160 }
161 return nil, err
162 }
163 // return an error with an fs which points to the parent
164 return f, fs.ErrorIsFile
165 }
166
167 return f, nil
168}

Callers

nothing calls this directly

Calls 9

NewObjectMethod · 0.95
SetFunction · 0.92
NewClientFunction · 0.92
NewClientFunction · 0.92
NewFunction · 0.92
rootSplitFunction · 0.85
SetRootMethod · 0.80
FillMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…