diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-03-09 21:27:31 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-03-09 21:27:31 +0000 |
commit | ec5ac46e1fa894bef62bd0c65d4f5fac03e6df4d (patch) | |
tree | b70eddd674a9a16495f82b572c50e27e9e4fa3ba /dupfiles | |
parent | 5ca77b7816a34fa934c8ca3cb857cf66bc986c44 (diff) | |
download | dupfiles-ec5ac46e1fa894bef62bd0c65d4f5fac03e6df4d.tar.gz |
Always keep the copy in the last directory, if possible
Diffstat (limited to 'dupfiles')
-rwxr-xr-x | dupfiles | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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) |