// WriteObjectTo writes an object to the fs, remote passed in func (r *Run) WriteObjectTo(f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool) fstest.Item { put := f.Put if useUnchecked { if fPutUnchecked, ok := f.(fs.PutUncheckeder); ok { put = fPutUnchecked.PutUnchecked } else { r.Fatalf("Fs doesn't support PutUnchecked") } } const maxTries = 5 if !r.mkdir[f.String()] { err := f.Mkdir() if err != nil { r.Fatalf("Failed to mkdir %q: %v", f, err) } r.mkdir[f.String()] = true } for tries := 1; ; tries++ { in := bytes.NewBufferString(content) objinfo := fs.NewStaticObjectInfo(remote, modTime, int64(len(content)), true, nil, nil) _, err := put(in, objinfo) if err == nil { break } // Retry if err returned a retry error if fs.IsRetryError(err) && tries < maxTries { r.Logf("Retry Put of %q to %v: %d/%d (%v)", remote, f, tries, maxTries, err) continue } r.Fatalf("Failed to put %q to %q: %v", remote, f, err) } return fstest.NewItem(remote, content, modTime) }
// WriteObjectTo writes an object to the fs, remote passed in func (r *Run) WriteObjectTo(f fs.Fs, remote, content string, modTime time.Time, useUnchecked bool) fstest.Item { put := f.Put if useUnchecked { put = f.Features().PutUnchecked if put == nil { r.Fatalf("Fs doesn't support PutUnchecked") } } r.Mkdir(f) const maxTries = 10 for tries := 1; ; tries++ { in := bytes.NewBufferString(content) objinfo := fs.NewStaticObjectInfo(remote, modTime, int64(len(content)), true, nil, nil) _, err := put(in, objinfo) if err == nil { break } // Retry if err returned a retry error if fs.IsRetryError(err) && tries < maxTries { r.Logf("Retry Put of %q to %v: %d/%d (%v)", remote, f, tries, maxTries, err) time.Sleep(2 * time.Second) continue } r.Fatalf("Failed to put %q to %q: %v", remote, f, err) } return fstest.NewItem(remote, content, modTime) }
// Write a file to local func (r *Run) WriteFile(filePath, content string, t time.Time) fstest.Item { item := fstest.NewItem(filePath, content, t) // FIXME make directories? filePath = path.Join(r.localName, filePath) dirPath := path.Dir(filePath) err := os.MkdirAll(dirPath, 0770) if err != nil { r.Fatalf("Failed to make directories %q: %v", dirPath, err) } err = ioutil.WriteFile(filePath, []byte(content), 0600) if err != nil { r.Fatalf("Failed to write file %q: %v", filePath, err) } err = os.Chtimes(filePath, t, t) if err != nil { r.Fatalf("Failed to chtimes file %q: %v", filePath, err) } return item }
// WriteObjectTo writes an object to the fs, remote passed in func (r *Run) WriteObjectTo(f fs.Fs, remote, content string, modTime time.Time) fstest.Item { const maxTries = 5 if !r.mkdir[f.String()] { err := f.Mkdir() if err != nil { r.Fatalf("Failed to mkdir %q: %v", f, err) } r.mkdir[f.String()] = true } for tries := 1; ; tries++ { in := bytes.NewBufferString(content) _, err := f.Put(in, remote, modTime, int64(len(content))) if err == nil { break } // Retry if err returned a retry error if retry, ok := err.(fs.Retry); ok && retry.Retry() && tries < maxTries { r.Logf("Retry Put of %q to %v: %d/%d (%v)", remote, f, tries, maxTries, err) continue } r.Fatalf("Failed to put %q to %q: %v", remote, f, err) } return fstest.NewItem(remote, content, modTime) }