mirror of
https://github.com/rclone/rclone
synced 2024-12-19 09:05:56 +01:00
test_all: optionally run Cleanup before cleaning a remote
Add this to the QingStor remote to stop it running out of buckets
This commit is contained in:
parent
66e08e0cc8
commit
9a5178be7a
@ -19,16 +19,24 @@ import (
|
||||
var MatchTestRemote = regexp.MustCompile(`^rclone-test-[abcdefghijklmnopqrstuvwxyz0123456789]{24}(_segments)?$`)
|
||||
|
||||
// cleanFs runs a single clean fs for left over directories
|
||||
func cleanFs(remote string) error {
|
||||
func cleanFs(ctx context.Context, remote string, cleanup bool) error {
|
||||
f, err := fs.NewFs(remote)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
entries, err := list.DirSorted(context.Background(), f, true, "")
|
||||
var lastErr error
|
||||
if cleanup {
|
||||
log.Printf("%q - running cleanup", remote)
|
||||
err = operations.CleanUp(ctx, f)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
fs.Errorf(f, "Cleanup failed: %v", err)
|
||||
}
|
||||
}
|
||||
entries, err := list.DirSorted(ctx, f, true, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var lastErr error
|
||||
err = entries.ForDirError(func(dir fs.Directory) error {
|
||||
dirPath := dir.Remote()
|
||||
fullPath := remote + dirPath
|
||||
@ -45,7 +53,7 @@ func cleanFs(remote string) error {
|
||||
fs.Errorf(fullPath, "%v", err)
|
||||
return nil
|
||||
}
|
||||
err = operations.Purge(context.Background(), dir, "")
|
||||
err = operations.Purge(ctx, dir, "")
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "Purge failed")
|
||||
lastErr = err
|
||||
@ -62,11 +70,12 @@ func cleanFs(remote string) error {
|
||||
}
|
||||
|
||||
// cleanRemotes cleans the list of remotes passed in
|
||||
func cleanRemotes(remotes []string) error {
|
||||
func cleanRemotes(conf *Config) error {
|
||||
var lastError error
|
||||
for _, remote := range remotes {
|
||||
for _, backend := range conf.Backends {
|
||||
remote := backend.Remote
|
||||
log.Printf("%q - Cleaning", remote)
|
||||
err := cleanFs(remote)
|
||||
err := cleanFs(context.Background(), remote, backend.CleanUp)
|
||||
if err != nil {
|
||||
lastError = err
|
||||
log.Printf("Failed to purge %q: %v", remote, err)
|
||||
|
@ -33,6 +33,7 @@ type Backend struct {
|
||||
Short bool // set to test with -short
|
||||
OneOnly bool // set to run only one backend test at once
|
||||
MaxFile string // file size limit
|
||||
CleanUp bool // when running clean, run cleanup first
|
||||
Ignore []string // test names to ignore the failure of
|
||||
Tests []string // paths of tests to run, blank for all
|
||||
}
|
||||
@ -184,16 +185,3 @@ func (c *Config) filterTests(paths []string) {
|
||||
}
|
||||
c.Tests = newTests
|
||||
}
|
||||
|
||||
// Remotes returns the unique remotes
|
||||
func (c *Config) Remotes() (remotes []string) {
|
||||
found := map[string]struct{}{}
|
||||
for _, backend := range c.Backends {
|
||||
if _, ok := found[backend.Remote]; ok {
|
||||
continue
|
||||
}
|
||||
remotes = append(remotes, backend.Remote)
|
||||
found[backend.Remote] = struct{}{}
|
||||
}
|
||||
return remotes
|
||||
}
|
||||
|
@ -205,6 +205,7 @@ backends:
|
||||
remote: "TestQingStor:"
|
||||
fastlist: false
|
||||
oneonly: true
|
||||
cleanup: true
|
||||
- backend: "azureblob"
|
||||
remote: "TestAzureBlob:"
|
||||
fastlist: true
|
||||
|
@ -86,7 +86,7 @@ func main() {
|
||||
|
||||
// Just clean the directories if required
|
||||
if *clean {
|
||||
err := cleanRemotes(conf.Remotes())
|
||||
err := cleanRemotes(conf)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to clean: %v", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user