WriteObjectTo writes an object to the fs, remote passed in
(ctx context.Context, f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool)
| 253 | |
| 254 | // WriteObjectTo writes an object to the fs, remote passed in |
| 255 | func (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 |
| 296 | func (r *Run) WriteObject(ctx context.Context, remote, content string, modTime time.Time) Item { |