// RandomRemote makes a random bucket or subdirectory on the remote // // Call the finalise function returned to Purge the fs at the end (and // the parent if necessary) func RandomRemote(remoteName string, subdir bool) (fs.Fs, func(), error) { var err error var parentRemote fs.Fs remoteName, _, err = RandomRemoteName(remoteName) if err != nil { return nil, nil, err } if subdir { parentRemote, err = fs.NewFs(remoteName) if err != nil { return nil, nil, err } remoteName += "/rclone-test-subdir-" + RandomString(8) } remote, err := fs.NewFs(remoteName) if err != nil { return nil, nil, err } finalise := func() { _ = fs.Purge(remote) // ignore error if parentRemote != nil { err = fs.Purge(parentRemote) // ignore error if err != nil { log.Printf("Failed to purge %v: %v", parentRemote, err) } } } return remote, finalise, nil }
// TestPurge tests Purge works func TestPurge(t *testing.T, remote fs.Fs) { err := fs.Purge(remote) if err != nil { t.Fatalf("Purge failed: %v", err) } CheckListing(t, remote, []Item{}) }
func TestObjectPurge(t *testing.T) { skipIfNotOk(t) fstest.TestPurge(t, remote) err := fs.Purge(remote) if err == nil { t.Fatal("Expecting error after on second purge") } }
// Test a server side move if possible, or the backup path if not func testServerSideMove(t *testing.T, r *Run, fremoteMove fs.Fs, withFilter bool) { file1 := r.WriteBoth("potato2", "------------------------------------------------------------", t1) file2 := r.WriteBoth("empty space", "", t2) file3u := r.WriteBoth("potato3", "------------------------------------------------------------ UPDATED", t2) fstest.CheckItems(t, r.fremote, file2, file1, file3u) t.Logf("Server side move (if possible) %v -> %v", r.fremote, fremoteMove) // Write just one file in the new remote r.WriteObjectTo(fremoteMove, "empty space", "", t2, false) file3 := r.WriteObjectTo(fremoteMove, "potato3", "------------------------------------------------------------", t1, false) fstest.CheckItems(t, fremoteMove, file2, file3) // Do server side move fs.Stats.ResetCounters() err := fs.MoveDir(fremoteMove, r.fremote) require.NoError(t, err) if withFilter { fstest.CheckItems(t, r.fremote, file2) } else { fstest.CheckItems(t, r.fremote) } fstest.CheckItems(t, fremoteMove, file2, file1, file3u) // Purge the original before moving require.NoError(t, fs.Purge(r.fremote)) // Move it back again, dst does not exist this time fs.Stats.ResetCounters() err = fs.MoveDir(r.fremote, fremoteMove) require.NoError(t, err) if withFilter { fstest.CheckItems(t, r.fremote, file1, file3u) fstest.CheckItems(t, fremoteMove, file2) } else { fstest.CheckItems(t, r.fremote, file2, file1, file3u) fstest.CheckItems(t, fremoteMove) } }
// cleanFs runs a single clean fs for left over directories func (t *test) cleanFs() error { f, err := fs.NewFs(t.remote) if err != nil { return err } for dir := range f.ListDir() { if fstest.MatchTestRemote.MatchString(dir.Name) { log.Printf("Purging %s%s", t.remote, dir.Name) dir, err := fs.NewFs(t.remote + dir.Name) if err != nil { return err } err = fs.Purge(dir) if err != nil { return err } } } return nil }
// cleanFs runs a single clean fs for left over directories func (t *test) cleanFs() error { f, err := fs.NewFs(t.remote) if err != nil { return err } dirs, err := fs.NewLister().SetLevel(1).Start(f, "").GetDirs() for _, dir := range dirs { if fstest.MatchTestRemote.MatchString(dir.Name) { log.Printf("Purging %s%s", t.remote, dir.Name) dir, err := fs.NewFs(t.remote + dir.Name) if err != nil { return err } err = fs.Purge(dir) if err != nil { return err } } } return nil }
// cleanFs runs a single clean fs for left over directories func (t *test) cleanFs() error { f, err := fs.NewFs(t.remote) if err != nil { return err } for dir := range f.ListDir() { insideDigits := len(findInteriorDigits.FindAllString(dir.Name, -1)) if matchTestRemote.MatchString(dir.Name) && insideDigits >= 2 { log.Printf("Purging %s%s", t.remote, dir.Name) dir, err := fs.NewFs(t.remote + dir.Name) if err != nil { return err } err = fs.Purge(dir) if err != nil { return err } } } return nil }
// TestObjectPurge tests Purge func TestObjectPurge(t *testing.T) { skipIfNotOk(t) fstest.TestPurge(t, remote) err := fs.Purge(remote) assert.Error(t, err, "Expecting error after on second purge") }
Remove the path. Note that you can't remove a path with objects in it, use purge for that.`, Run: func(fdst, fsrc fs.Fs) error { return fs.Rmdir(fdst) }, MinArgs: 1, MaxArgs: 1, Retry: true, }, { Name: "purge", ArgsHelp: "remote:path", Help: ` Remove the path and all of its contents.`, Run: func(fdst, fsrc fs.Fs) error { return fs.Purge(fdst) }, MinArgs: 1, MaxArgs: 1, Retry: true, }, { Name: "check", ArgsHelp: "source:path dest:path", Help: ` Checks the files in the source and destination match. It compares sizes and MD5SUMs and prints a report of files which don't match. It doesn't alter the source or destination.`, Run: func(fdst, fsrc fs.Fs) error { return fs.Check(fdst, fsrc) },
// TestPurge tests Purge works func TestPurge(t *testing.T, remote fs.Fs) { err := fs.Purge(remote) require.NoError(t, err) CheckListing(t, remote, []Item{}) }
Run: func(fdst, fsrc fs.Fs) { err := fs.Rmdir(fdst) if err != nil { log.Fatalf("Failed to rmdir: %v", err) } }, MinArgs: 1, MaxArgs: 1, }, { Name: "purge", ArgsHelp: "remote:path", Help: ` Remove the path and all of its contents.`, Run: func(fdst, fsrc fs.Fs) { err := fs.Purge(fdst) if err != nil { log.Fatalf("Failed to purge: %v", err) } }, MinArgs: 1, MaxArgs: 1, }, { Name: "check", ArgsHelp: "source:path dest:path", Help: ` Checks the files in the source and destination match. It compares sizes and MD5SUMs and prints a report of files which don't match. It doesn't alter the source or destination.`, Run: func(fdst, fsrc fs.Fs) {