[mirrorbrain-commits] [opensuse-svn] r7629 - trunk/tools/download-redirector-v2/tools

From: Novell Forge SVN <noreply_at_novell.com>
Date: Sat, 27 Jun 2009 07:52:49 -0600 (MDT)
Author: poeml
Date: 2009-06-27 07:52:43 -0600 (Sat, 27 Jun 2009)
New Revision: 7629

Modified:
   trunk/tools/download-redirector-v2/tools/metalink-hasher.py
Log:
metalink-hasher:
- using a "set" builtin type instead of a list can speed up finding obsolete
  files in the destination directory by 10 times, for huge directories.
- print a summary of deletions.


Modified: trunk/tools/download-redirector-v2/tools/metalink-hasher.py
===================================================================
--- trunk/tools/download-redirector-v2/tools/metalink-hasher.py	2009-06-27 01:07:18 UTC (rev 7628)
+++ trunk/tools/download-redirector-v2/tools/metalink-hasher.py	2009-06-27 13:52:43 UTC (rev 7629)
@@ -161,6 +161,8 @@
         if opts.file_mask: 
             opts.file_mask = re.compile(opts.file_mask)
 
+        unlinked_files = unlinked_dirs = 0
+
         while len(directories_todo) > 0:
             src_dir = directories_todo.pop()
 
@@ -176,8 +178,7 @@
                 else:
                     os.chmod(dst_dir, 0755)
 
-            src_names = os.listdir(src_dir)
-            src_names.sort()
+            src_names = set(os.listdir(src_dir))
             try:
                 dst_names = os.listdir(dst_dir)
                 dst_names.sort()
@@ -198,19 +199,22 @@
                         if not opts.dry_run: 
                             try:
                                 os.unlink(i_path)
-                            except:
-                                print 'unlinking failed:', i_path
+                            except OSError, e:
+                                print 'Unlink failed for %r: %s' % (i_path, e.errno)
+                        unlinked_files += 1
                 # removal of obsolete directories
                 else:
-                    if i not in src_names:
+                    if i not in sorted(src_names):
                         if os.path.isdir(i_path):
                             print 'Recursively removing obsolete directory %r' % i_path
                             if not opts.dry_run: 
                                 shutil.rmtree(i_path)
+                            unlinked_dirs += 1
                         else:
                             print 'Unlinking obsolete %r' % i_path
                             if not opts.dry_run: 
                                 os.unlink(i_path)
+                            unlinked_files += 1
 
             for src_name in src_names:
 
@@ -240,6 +244,11 @@
                     directories_todo.append(src)  # It's a directory, store it.
 
 
+        if  unlinked_files or unlinked_dirs:
+            print 'Unlinked %s files, %d directories.' % (unlinked_files, unlinked_dirs)
+
+
+
 if __name__ == '__main__':
     import sys
     metalinks = Metalinks()

_______________________________________________
Opensuse-svn mailing list
Opensuse-svn_at_forge.novell.com
http://forge.novell.com/mailman/listinfo/opensuse-svn


_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on 2009-06-27Z13:53:10

This archive was generated by hypermail 2.2.0 : 2009-07-10Z19:18:13 GMT