forked from TrueCloudLab/rclone
Add --dedupe-mode only to dedupe command
This commit is contained in:
parent
412591dfaf
commit
ae56df7d4f
3 changed files with 35 additions and 23 deletions
19
fs/config.go
19
fs/config.go
|
@ -85,7 +85,6 @@ var (
|
||||||
lowLevelRetries = pflag.IntP("low-level-retries", "", 10, "Number of low level retries to do.")
|
lowLevelRetries = pflag.IntP("low-level-retries", "", 10, "Number of low level retries to do.")
|
||||||
updateOlder = pflag.BoolP("update", "u", false, "Skip files that are newer on the destination.")
|
updateOlder = pflag.BoolP("update", "u", false, "Skip files that are newer on the destination.")
|
||||||
noGzip = pflag.BoolP("no-gzip-encoding", "", false, "Don't set Accept-Encoding: gzip.")
|
noGzip = pflag.BoolP("no-gzip-encoding", "", false, "Don't set Accept-Encoding: gzip.")
|
||||||
dedupeMode = pflag.StringP("dedupe-mode", "", "interactive", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
|
||||||
maxDepth = pflag.IntP("max-depth", "", -1, "If set limits the recursion depth to this.")
|
maxDepth = pflag.IntP("max-depth", "", -1, "If set limits the recursion depth to this.")
|
||||||
ignoreSize = pflag.BoolP("ignore-size", "", false, "Ignore size when skipping use mod-time or checksum.")
|
ignoreSize = pflag.BoolP("ignore-size", "", false, "Ignore size when skipping use mod-time or checksum.")
|
||||||
noTraverse = pflag.BoolP("no-traverse", "", false, "Don't traverse destination file system on copy.")
|
noTraverse = pflag.BoolP("no-traverse", "", false, "Don't traverse destination file system on copy.")
|
||||||
|
@ -237,7 +236,6 @@ type ConfigInfo struct {
|
||||||
LowLevelRetries int
|
LowLevelRetries int
|
||||||
UpdateOlder bool // Skip files that are newer on the destination
|
UpdateOlder bool // Skip files that are newer on the destination
|
||||||
NoGzip bool // Disable compression
|
NoGzip bool // Disable compression
|
||||||
DedupeMode DeduplicateMode
|
|
||||||
MaxDepth int
|
MaxDepth int
|
||||||
IgnoreSize bool
|
IgnoreSize bool
|
||||||
NoTraverse bool
|
NoTraverse bool
|
||||||
|
@ -355,23 +353,6 @@ func LoadConfig() {
|
||||||
Config.DeleteDuring = *deleteDuring
|
Config.DeleteDuring = *deleteDuring
|
||||||
Config.DeleteAfter = *deleteAfter
|
Config.DeleteAfter = *deleteAfter
|
||||||
|
|
||||||
switch strings.ToLower(*dedupeMode) {
|
|
||||||
case "interactive":
|
|
||||||
Config.DedupeMode = DeduplicateInteractive
|
|
||||||
case "skip":
|
|
||||||
Config.DedupeMode = DeduplicateSkip
|
|
||||||
case "first":
|
|
||||||
Config.DedupeMode = DeduplicateFirst
|
|
||||||
case "newest":
|
|
||||||
Config.DedupeMode = DeduplicateNewest
|
|
||||||
case "oldest":
|
|
||||||
Config.DedupeMode = DeduplicateOldest
|
|
||||||
case "rename":
|
|
||||||
Config.DedupeMode = DeduplicateRename
|
|
||||||
default:
|
|
||||||
log.Fatalf(`Unknown mode for --dedupe-mode %q.`, *dedupeMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case *deleteBefore && (*deleteDuring || *deleteAfter),
|
case *deleteBefore && (*deleteDuring || *deleteAfter),
|
||||||
*deleteDuring && *deleteAfter:
|
*deleteDuring && *deleteAfter:
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ogier/pflag"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"golang.org/x/text/unicode/norm"
|
"golang.org/x/text/unicode/norm"
|
||||||
|
@ -871,8 +872,8 @@ const (
|
||||||
DeduplicateRename // rename the objects
|
DeduplicateRename // rename the objects
|
||||||
)
|
)
|
||||||
|
|
||||||
func (mode DeduplicateMode) String() string {
|
func (x DeduplicateMode) String() string {
|
||||||
switch mode {
|
switch x {
|
||||||
case DeduplicateInteractive:
|
case DeduplicateInteractive:
|
||||||
return "interactive"
|
return "interactive"
|
||||||
case DeduplicateSkip:
|
case DeduplicateSkip:
|
||||||
|
@ -889,6 +890,35 @@ func (mode DeduplicateMode) String() string {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set a DeduplicateMode from a string
|
||||||
|
func (x *DeduplicateMode) Set(s string) error {
|
||||||
|
switch strings.ToLower(s) {
|
||||||
|
case "interactive":
|
||||||
|
*x = DeduplicateInteractive
|
||||||
|
case "skip":
|
||||||
|
*x = DeduplicateSkip
|
||||||
|
case "first":
|
||||||
|
*x = DeduplicateFirst
|
||||||
|
case "newest":
|
||||||
|
*x = DeduplicateNewest
|
||||||
|
case "oldest":
|
||||||
|
*x = DeduplicateOldest
|
||||||
|
case "rename":
|
||||||
|
*x = DeduplicateRename
|
||||||
|
default:
|
||||||
|
return errors.Errorf("Unknown mode for dedupe %q.", s)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type of the value
|
||||||
|
func (x *DeduplicateMode) Type() string {
|
||||||
|
return "string"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check it satisfies the interface
|
||||||
|
var _ pflag.Value = (*DeduplicateMode)(nil)
|
||||||
|
|
||||||
// Deduplicate interactively finds duplicate files and offers to
|
// Deduplicate interactively finds duplicate files and offers to
|
||||||
// delete all but one or rename them to be different. Only useful with
|
// delete all but one or rename them to be different. Only useful with
|
||||||
// Google Drive which can have duplicate file names.
|
// Google Drive which can have duplicate file names.
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
// FIXME only attach the remote flags when using a remote???
|
// FIXME only attach the remote flags when using a remote???
|
||||||
// FIXME could do the same for dedupe
|
|
||||||
// would probably mean bringing all the flags in to here? Or define some flagsets in fs...
|
// would probably mean bringing all the flags in to here? Or define some flagsets in fs...
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -32,6 +31,7 @@ var (
|
||||||
version bool
|
version bool
|
||||||
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
|
logFile = pflag.StringP("log-file", "", "", "Log everything to this file")
|
||||||
retries = pflag.IntP("retries", "", 3, "Retry operations this many times if they fail")
|
retries = pflag.IntP("retries", "", 3, "Retry operations this many times if they fail")
|
||||||
|
dedupeMode = fs.DeduplicateInteractive
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -82,6 +82,7 @@ func init() {
|
||||||
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
||||||
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
||||||
configCmd, authorizeCmd, cleanupCmd, versionCmd)
|
configCmd, authorizeCmd, cleanupCmd, versionCmd)
|
||||||
|
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,7 +447,7 @@ Google Drive which can have duplicate file names.`,
|
||||||
checkArgs(1, 1, cmd, args)
|
checkArgs(1, 1, cmd, args)
|
||||||
fdst := NewFsSrc(args[1])
|
fdst := NewFsSrc(args[1])
|
||||||
run(false, cmd, func() error {
|
run(false, cmd, func() error {
|
||||||
return fs.Deduplicate(fdst, fs.Config.DedupeMode)
|
return fs.Deduplicate(fdst, dedupeMode)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue