summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-03-09 21:27:31 +0000
committerLars Wirzenius <liw@liw.fi>2012-03-09 21:27:31 +0000
commitec5ac46e1fa894bef62bd0c65d4f5fac03e6df4d (patch)
treeb70eddd674a9a16495f82b572c50e27e9e4fa3ba
parent5ca77b7816a34fa934c8ca3cb857cf66bc986c44 (diff)
downloaddupfiles-ec5ac46e1fa894bef62bd0c65d4f5fac03e6df4d.tar.gz
Always keep the copy in the last directory, if possible
-rwxr-xr-xdupfiles15
1 files changed, 12 insertions, 3 deletions
diff --git a/dupfiles b/dupfiles
index ad189a8..61b0d4d 100755
--- a/dupfiles
+++ b/dupfiles
@@ -216,7 +216,7 @@ class Dupfiles(cliapp.Application):
if self.settings['make-hardlinks']:
self.make_hardlinks(duplicates)
elif self.settings['remove']:
- self.remove_all_but_one(duplicates)
+ self.remove_all_but_one(duplicates, args[-1])
else:
self.report(duplicates)
@@ -236,8 +236,17 @@ class Dupfiles(cliapp.Application):
os.remove(pathname)
os.link(canonical, pathname)
- def remove_all_but_one(self, duplicates):
- keep = duplicates.pop()
+ def remove_all_but_one(self, duplicates, last_dir):
+ if not last_dir.endswith(os.sep):
+ last_dir += os.sep
+ for pathname in duplicates:
+ if pathname.startswith(last_dir):
+ keep = pathname
+ duplicates.remove(keep)
+ break
+ else:
+ keep = duplicates.pop()
+
for pathname in duplicates:
if self.settings['no-act']:
self.output.write('rm %s\n' % pathname)