mirror of https://github.com/rclone/rclone.git
test info: improve cleanup of temp files - fixes #7209
Co-authored-by: Kyle Reynolds <kyle.reynolds@bridgerphotonics.com>
This commit is contained in:
parent
998df26ceb
commit
f6e716543a
|
@ -27,12 +27,14 @@ import (
|
||||||
"github.com/rclone/rclone/fs/config/flags"
|
"github.com/rclone/rclone/fs/config/flags"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
"github.com/rclone/rclone/fs/object"
|
"github.com/rclone/rclone/fs/object"
|
||||||
|
"github.com/rclone/rclone/fs/operations"
|
||||||
"github.com/rclone/rclone/lib/random"
|
"github.com/rclone/rclone/lib/random"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
writeJSON string
|
writeJSON string
|
||||||
|
keepTestFiles bool
|
||||||
checkNormalization bool
|
checkNormalization bool
|
||||||
checkControl bool
|
checkControl bool
|
||||||
checkLength bool
|
checkLength bool
|
||||||
|
@ -56,6 +58,7 @@ func init() {
|
||||||
flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", false, "Check uploads with indeterminate file size", "")
|
flags.BoolVarP(cmdFlags, &checkStreaming, "check-streaming", "", false, "Check uploads with indeterminate file size", "")
|
||||||
flags.BoolVarP(cmdFlags, &checkBase32768, "check-base32768", "", false, "Check can store all possible base32768 characters", "")
|
flags.BoolVarP(cmdFlags, &checkBase32768, "check-base32768", "", false, "Check can store all possible base32768 characters", "")
|
||||||
flags.BoolVarP(cmdFlags, &all, "all", "", false, "Run all tests", "")
|
flags.BoolVarP(cmdFlags, &all, "all", "", false, "Run all tests", "")
|
||||||
|
flags.BoolVarP(cmdFlags, &keepTestFiles, "keep-test-files", "", false, "Keep test files after execution", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commandDefinition = &cobra.Command{
|
var commandDefinition = &cobra.Command{
|
||||||
|
@ -84,7 +87,15 @@ a bit of go code for each one.
|
||||||
checkBase32768 = true
|
checkBase32768 = true
|
||||||
}
|
}
|
||||||
for i := range args {
|
for i := range args {
|
||||||
f := cmd.NewFsDir(args[i : i+1])
|
tempDirName := "rclone-test-info-" + random.String(8)
|
||||||
|
tempDirPath := path.Join(args[i], tempDirName)
|
||||||
|
f := cmd.NewFsDir([]string{tempDirPath})
|
||||||
|
fs.Infof(f, "Created temporary directory for test files: %s", tempDirPath)
|
||||||
|
err := f.Mkdir(context.Background(), "")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("couldn't create temporary directory: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
cmd.Run(false, false, command, func() error {
|
cmd.Run(false, false, command, func() error {
|
||||||
return readInfo(context.Background(), f)
|
return readInfo(context.Background(), f)
|
||||||
})
|
})
|
||||||
|
@ -471,10 +482,18 @@ func (r *results) checkStreaming() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInfo(ctx context.Context, f fs.Fs) error {
|
func readInfo(ctx context.Context, f fs.Fs) error {
|
||||||
err := f.Mkdir(ctx, "")
|
// Ensure cleanup unless --keep-test-files is specified
|
||||||
if err != nil {
|
if !keepTestFiles {
|
||||||
return fmt.Errorf("couldn't mkdir: %w", err)
|
defer func() {
|
||||||
|
err := operations.Purge(ctx, f, "")
|
||||||
|
if err != nil {
|
||||||
|
fs.Errorf(f, "Failed to purge temporary directory: %v", err)
|
||||||
|
} else {
|
||||||
|
fs.Infof(f, "Removed temporary directory for test files: %s", f.Root())
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
r := newResults(ctx, f)
|
r := newResults(ctx, f)
|
||||||
if checkControl {
|
if checkControl {
|
||||||
r.checkControls()
|
r.checkControls()
|
||||||
|
|
Loading…
Reference in New Issue