From fd95a11c31de2cc8443e7a7d0da9a437c86ef9ee Mon Sep 17 00:00:00 2001 From: Ishan Goel Date: Sat, 24 Dec 2022 18:33:29 -0800 Subject: [PATCH] Make timestamps actually work --- rem.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rem.go b/rem.go index 2e052ba..4443982 100644 --- a/rem.go +++ b/rem.go @@ -261,7 +261,6 @@ func trashFile(path string) { return } toMoveTo = getTimestampedPath(toMoveTo, exists) - path = getTimestampedPath(path, existsInLog) if flags.moveByCopyOk { err = renameByCopyAllowed(path, toMoveTo) } else { @@ -273,7 +272,14 @@ func trashFile(path string) { } absPath, _ := filepath.Abs(path) - logFile[absPath] = toMoveTo // format is path where it came from ==> path in trash + + // make sure there are no conflicts in the log + timestamped := getTimestampedPath(absPath, existsInLog) + + if timestamped != absPath { + printIfNotQuiet("To avoid conflicts, " + color.YellowString(filepath.Base(absPath)) + " will now be called " + color.YellowString(filepath.Base(timestamped))) + } + logFile[timestamped] = toMoveTo // format is path where it came from ==> path in trash setLogFile(logFile) // if we've reached here, trashing is complete and successful if flags.rmMode { @@ -326,9 +332,6 @@ func getTimestampedPath(path string, existsFunc func(string) bool) string { path = oldPath + " " + strconv.FormatInt(rand.Int63(), 10) // add random stuff at the end } } - if i != 0 { - printIfNotQuiet("To avoid conflicts, " + color.YellowString(oldPath) + " will now be called " + color.YellowString(path)) - } return path }