"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "fslint/supprt/rmlint/fixdup" between
fslint-2.44.tar.gz and fslint-2.46.tar.gz

About: fslint is a toolkit to find and clean various forms of lint on a filesystem (for e.g. duplicate files).

fixdup  (fslint-2.44):fixdup  (fslint-2.46)
#!/usr/bin/env python #!/usr/bin/env python2
# This is called by findup automatically don't call explicitly # This is called by findup automatically don't call explicitly
# unless you really know what you're doing. # unless you really know what you're doing.
# #
# It expects lines in the format: # It expects lines in the format:
# filename1 # filename1
# filename2 # filename2
# #
# filename3 # filename3
# filename4 # filename4
# ... # ...
import sys, string, os, tempfile, errno import sys, string, os, tempfile, errno
symlink=0
link=1 link=1
dryRun=0 dryRun=0
if len(sys.argv) == 2: if len(sys.argv) == 2:
if sys.argv[1] == "del": if sys.argv[1] == "del":
link=0 link=0
elif sys.argv[1] == "tdel": elif sys.argv[1] == "tdel":
link=0 link=0
dryRun=1 dryRun=1
elif sys.argv[1] == "tmerge": elif sys.argv[1] == "tmerge":
dryRun=1 dryRun=1
elif sys.argv[1] == "symlink":
symlink=1
elif sys.argv[1] == "tsymlink":
symlink=1
dryRun=1
ingroup = 0 ingroup = 0
for line in sys.stdin: for line in sys.stdin:
line = line[:-1] line = line[:-1]
if line == '': if line == '':
ingroup = 0 ingroup = 0
else: else:
if not ingroup: if not ingroup:
keepfile = line keepfile = line
ingroup = 1 ingroup = 1
if dryRun: if dryRun:
sys.stdout.write("\n\nkeeping: " + keepfile + "\n") sys.stdout.write("\n\nkeeping: " + keepfile + "\n")
if link: if symlink:
sys.stdout.write("symlinking: ")
elif link:
sys.stdout.write("hardlinking: ") sys.stdout.write("hardlinking: ")
else: else:
sys.stdout.write("deleting: ") sys.stdout.write("deleting: ")
else: else:
if dryRun: if dryRun:
sys.stdout.write(line+' ') sys.stdout.write(line+' ')
else: else:
dupfile = line dupfile = line
dupdir = os.path.dirname(dupfile) dupdir = os.path.dirname(dupfile)
tmpfile = tempfile.mktemp(dir=dupdir) tmpfile = tempfile.mktemp(dir=dupdir)
try: try:
if link: if link:
try: try:
os.link(keepfile,tmpfile) if symlink:
os.symlink(os.path.realpath(keepfile),tmpfile)
else:
os.link(keepfile,tmpfile)
except OSError, value: except OSError, value:
if value.errno == errno.EXDEV: if value.errno == errno.EXDEV and not symlink:
os.symlink(os.path.realpath(keepfile),tmpfile) os.symlink(os.path.realpath(keepfile),tmpfile)
else: else:
raise raise
os.rename(tmpfile, dupfile) os.rename(tmpfile, dupfile)
else: else:
os.unlink(dupfile) os.unlink(dupfile)
except OSError: except OSError:
sys.stderr.write(str(sys.exc_info()[1])+'\n') sys.stderr.write(str(sys.exc_info()[1])+'\n')
try: try:
#always try this as POSIX has bad requirement that #always try this as POSIX has bad requirement that
 End of changes. 6 change blocks. 
4 lines changed or deleted 16 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS