MCPcopy
hub / github.com/rclone/rclone / WriteObjectTo

Method WriteObjectTo

fstest/run.go:255–293  ·  view source on GitHub ↗

WriteObjectTo writes an object to the fs, remote passed in

(ctx context.Context, f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool)

Source from the content-addressed store, hash-verified

253
254// WriteObjectTo writes an object to the fs, remote passed in
255func (r *Run) WriteObjectTo(ctx context.Context, f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool) Item {
256 put := f.Put
257 if useUnchecked {
258 put = f.Features().PutUnchecked
259 if put == nil {
260 r.Fatalf("Fs doesn't support PutUnchecked")
261 }
262 }
263 r.Mkdir(ctx, f)
264
265 // calculate all hashes f supports for content
266 hash, err := hash.NewMultiHasherTypes(f.Hashes())
267 if err != nil {
268 r.Fatalf("Failed to make new multi hasher: %v", err)
269 }
270 _, err = hash.Write([]byte(content))
271 if err != nil {
272 r.Fatalf("Failed to make write to hash: %v", err)
273 }
274 hashSums := hash.Sums()
275
276 const maxTries = 10
277 for tries := 1; ; tries++ {
278 in := bytes.NewBufferString(content)
279 objinfo := object.NewStaticObjectInfo(remote, modTime, int64(len(content)), true, hashSums, nil)
280 _, err := put(ctx, in, objinfo)
281 if err == nil {
282 break
283 }
284 // Retry if err returned a retry error
285 if fserrors.IsRetryError(err) && tries < maxTries {
286 r.Logf("Retry Put of %q to %v: %d/%d (%v)", remote, f, tries, maxTries, err)
287 time.Sleep(2 * time.Second)
288 continue
289 }
290 r.Fatalf("Failed to put %q to %q: %v", remote, f, err)
291 }
292 return NewItem(remote, content, modTime)
293}
294
295// WriteObject writes an object to the remote
296func (r *Run) WriteObject(ctx context.Context, remote, content string, modTime time.Time) Item {

Callers 4

TestSymlinkFunction · 0.95
WriteObjectMethod · 0.95
WriteUncheckedObjectMethod · 0.95
testServerSideMoveFunction · 0.80

Calls 10

MkdirMethod · 0.95
NewStaticObjectInfoFunction · 0.92
IsRetryErrorFunction · 0.92
NewItemFunction · 0.85
FatalfMethod · 0.80
SumsMethod · 0.80
LogfMethod · 0.80
FeaturesMethod · 0.65
HashesMethod · 0.65
WriteMethod · 0.65

Tested by 2

TestSymlinkFunction · 0.76
testServerSideMoveFunction · 0.64