func storageCopy(source environs.Storage, sourcePath string, target environs.Storage, targetPath string) error { rc, err := source.Get(sourcePath) if err != nil { return err } var buf bytes.Buffer _, err = io.Copy(&buf, rc) rc.Close() if err != nil { return err } return target.Put(targetPath, &buf, int64(buf.Len())) }
func checkRemoveAll(c *C, storage environs.Storage) { contents := []byte("File contents.") aFile := "a-file.txt" err := storage.Put(aFile, bytes.NewBuffer(contents), int64(len(contents))) c.Assert(err, IsNil) err = storage.Put("empty-file", bytes.NewBuffer(nil), 0) c.Assert(err, IsNil) err = storage.RemoveAll() c.Assert(err, IsNil) files, err := storage.List("") c.Assert(err, IsNil) c.Check(files, HasLen, 0) _, err = storage.Get(aFile) c.Assert(err, NotNil) c.Check(err, ErrorMatches, fmt.Sprintf("file %q not found", aFile)) }