diff --git a/config/config.go b/config/config.go index d3008d5..9b4fb53 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,7 @@ import ( "strings" ) +// Load reads and parses the first config that can be found. func Load() ([]string, error) { var kvs []string configPath, err := findConfigFile() diff --git a/copy.go b/copy.go index 7497c8e..f66215a 100644 --- a/copy.go +++ b/copy.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strconv" + "fmt" ) var buffersize uint = 32768 @@ -39,6 +40,8 @@ func copyLoop() { filepath.Base(sourcePath)) filesLock.Unlock() + + os.Remove(destPath) copyFilePath(sourcePath, destPath) } else if i < len(fileOrder) { @@ -57,19 +60,26 @@ func copyLoop() { // check if file already exists and we even care about that: var doCopy bool = true - if onExistingFile != 1 { - stat, err := os.Lstat(destPath) - if err == nil && stat != nil { + stat, err := os.Lstat(destPath) + if err == nil && stat != nil { + // file exists + switch onExistingFile { + case Skip: + doCopy = false + case Overwrite: + os.Remove(destPath) + case Ask: + // save it to the conflicts: + filesLock.Lock() + piledConflicts = append(piledConflicts, i) + filesLock.Unlock() + doCopy = false + default: + // better safe than sorry doCopy = false - // file exists - if onExistingFile == 2 { - // save it to the conflicts: - filesLock.Lock() - piledConflicts = append(piledConflicts, i) - filesLock.Unlock() - } } } + if doCopy { copyFilePath(sourcePath, destPath) doneAmount += 1 @@ -108,6 +118,7 @@ func copyLoop() { * dest will be created as a link that links to that file as well. */ func copyFilePath(sourcePath string, destPath string) { + fmt.Printf("Copying %s to %s\n\n\n\n\n\n\n\n\n", sourcePath, destPath) var err error if doReflinks > 0 { err = reflink(sourcePath, destPath, &doneSize) diff --git a/flags.go b/flags.go index 7165cc6..ae8c436 100644 --- a/flags.go +++ b/flags.go @@ -54,6 +54,19 @@ var doReflinks uint8 = 0 var progressLSColors bool = false +// readConfig checks if the config should be read. +func readConfig() bool { + for _, arg := range os.Args { + if arg == "--" { + return false + } else if arg == "--no-config" { + return true + } + } + + return false +} + func parseKeyValue(key string, value string) { // Trim away spaces and tabs: key = strings.ToLower(strings.Trim(key, " \t'\"")) @@ -167,8 +180,6 @@ func parseFlag(prefix string, flag string) { onExistingFile = Overwrite case "i", "interactive": onExistingFile = Ask - case "no-config": - doReadConfig = false case "color": color.Init(true) case "reflink": diff --git a/main.go b/main.go index f9041f4..78b8310 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( "path/filepath" "strings" "sync" + "fmt" "time" ) @@ -51,8 +52,6 @@ const ( ModeRemove ) -var doReadConfig bool = true - // Maybe these are too small: // uint64 goes up to 18446744073709551615 // or 2097152 TB @@ -63,8 +62,8 @@ func main() { var err error color.Init(color.AutoColors()) - parseArgs() - if doReadConfig { + + if readConfig() { var kvs []string kvs, err = config.Load() if err == nil { @@ -75,6 +74,7 @@ func main() { warnConfig(err) } } + parseArgs() if verbose >= VerbInfo { printVersion() @@ -122,6 +122,7 @@ func main() { } else { // if there is more than one source, we want to copy the files // into the target directory: + fmt.Println("ups:", unsearchedPaths) stat, err := os.Stat(targetBase) if os.IsNotExist(err) { os.MkdirAll(targetBase, 0o755) diff --git a/ui.go b/ui.go index 47256d0..23801dd 100644 --- a/ui.go +++ b/ui.go @@ -284,7 +284,7 @@ func errEmptySource() { func errTargetNoDir(file string) { fmt.Print(color.FGColors.Red) - fmt.Print(file, "is not a directory.") + fmt.Print(file, " is not a directory.") fmt.Println(color.Text.Reset) os.Exit(2) }