"Fossies" - the Fresh Open Source Software Archive

Member "fslint-2.46/fslint/supprt/rmlint/fixdup" (2 Feb 2017, 2525 Bytes) of package /linux/privat/fslint-2.46.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "fixdup": 2.44_vs_2.46.

    1 #!/usr/bin/env python2
    2 
    3 # This is called by findup automatically don't call explicitly
    4 # unless you really know what you're doing.
    5 #
    6 # It expects lines in the format:
    7 # filename1
    8 # filename2
    9 #
   10 # filename3
   11 # filename4
   12 # ...
   13 
   14 import sys, string, os, tempfile, errno
   15 
   16 symlink=0
   17 link=1
   18 dryRun=0
   19 if len(sys.argv) == 2:
   20     if sys.argv[1] == "del":
   21         link=0
   22     elif sys.argv[1] == "tdel":
   23         link=0
   24         dryRun=1
   25     elif sys.argv[1] == "tmerge":
   26         dryRun=1
   27     elif sys.argv[1] == "symlink":
   28         symlink=1
   29     elif sys.argv[1] == "tsymlink":
   30         symlink=1
   31         dryRun=1
   32 
   33 ingroup = 0
   34 for line in sys.stdin:
   35     line = line[:-1]
   36     if line == '':
   37         ingroup = 0
   38     else:
   39         if not ingroup:
   40             keepfile = line
   41             ingroup = 1
   42             if dryRun:
   43                 sys.stdout.write("\n\nkeeping:     " + keepfile + "\n")
   44                 if symlink:
   45                     sys.stdout.write("symlinking: ")
   46                 elif link:
   47                     sys.stdout.write("hardlinking: ")
   48                 else:
   49                     sys.stdout.write("deleting: ")
   50         else:
   51             if dryRun:
   52                 sys.stdout.write(line+' ')
   53             else:
   54                 dupfile = line
   55                 dupdir = os.path.dirname(dupfile)
   56                 tmpfile = tempfile.mktemp(dir=dupdir)
   57                 try:
   58                     if link:
   59                         try:
   60                             if symlink:
   61                                 os.symlink(os.path.realpath(keepfile),tmpfile)
   62                             else:
   63                                 os.link(keepfile,tmpfile)
   64                         except OSError, value:
   65                             if value.errno == errno.EXDEV and not symlink:
   66                                 os.symlink(os.path.realpath(keepfile),tmpfile)
   67                             else:
   68                                 raise
   69                         os.rename(tmpfile, dupfile)
   70                     else:
   71                         os.unlink(dupfile)
   72                 except OSError:
   73                     sys.stderr.write(str(sys.exc_info()[1])+'\n')
   74                 try:
   75                     #always try this as POSIX has bad requirement that
   76                     #rename(file1,file2) where both are links to the same
   77                     #file, does nothing, and returns success. So if user
   78                     #merges files multiple times, tmp files will be left.
   79                     os.unlink(tmpfile)
   80                 except:
   81                     pass