]> arthur.barton.de Git - bup.git/commitdiff
Change "bup meta" to use recursive_dirlist() to add support for --xdev.
authorRob Browning <rlb@defaultvalue.org>
Thu, 4 Nov 2010 03:35:29 +0000 (22:35 -0500)
committerRob Browning <rlb@defaultvalue.org>
Thu, 4 Nov 2010 03:35:29 +0000 (22:35 -0500)
cmd/meta-cmd.py
lib/bup/metadata.py

index 2e5cbe97910b314c39cc4c101ffb93c32ee13c64..f1f5a7b27dd983b09d06022ca8c631ecd3fab002 100755 (executable)
@@ -26,6 +26,7 @@ start-extract  build tree matching metadata provided on standard input (or --fil
 finish-extract finish applying standard input (or --file) metadata to filesystem
 f,file=        specify source or destination file
 R,recurse      recurse into subdirectories
+xdev,one-file-system  don't cross filesystem boundaries
 numeric-ids    apply numeric IDs (user, group, etc.), not names, during restore
 symlinks       handle symbolic links (default is true)
 paths          include paths in metadata (default is true)
@@ -39,6 +40,7 @@ should_recurse = False
 restore_numeric_ids = False
 include_paths = True
 handle_symlinks = True
+xdev = False
 
 handle_ctrl_c()
 
@@ -62,6 +64,10 @@ for flag, value in flags:
         should_recurse = True
     elif flag == '--no-recurse':
         should_recurse = False
+    elif flag in frozenset(['--xdev', '--one-file-system']):
+        xdev = True
+    elif flag in frozenset(['--no-xdev', '--no-one-file-system']):
+        xdev = False
     elif flag == '--numeric-ids':
         restore_numeric_ids = True
     elif flag == '--no-numeric-ids':
@@ -93,7 +99,8 @@ if action == 'create':
                        remainder,
                        recurse=should_recurse,
                        write_paths=include_paths,
-                       save_symlinks=handle_symlinks)
+                       save_symlinks=handle_symlinks,
+                       xdev=xdev)
 
 elif action == 'list':
     if len(remainder) > 0:
index 117df31318983044d484c5618d486951e8b735e2..3042a37c3345043eaf0c74ea8feb3a5f5799155f 100644 (file)
@@ -9,6 +9,7 @@ import errno, os, sys, stat, pwd, grp, struct, xattr, posix1e, re
 
 from cStringIO import StringIO
 from bup import vint
+from bup.drecurse import recursive_dirlist
 from bup.helpers import add_error, mkdirp, log
 from bup.xstat import utime, lutime, lstat, FSTime
 import bup._helpers as _helpers
@@ -532,38 +533,33 @@ def from_path(path, archive_path=None, save_symlinks=True):
 def save_tree(output_file, paths,
               recurse=False,
               write_paths=True,
-              save_symlinks=True):
-    for p in paths:
-        safe_path = _clean_up_path_for_archive(p)
-        if(safe_path != p):
-            log('bup: archiving "%s" as "%s"\n' % (p, safe_path))
-
-        # Handle path itself.
-        try:
-            m = from_path(p, archive_path=safe_path,
-                          save_symlinks=save_symlinks)
-        except MetadataAcquisitionError, e:
-            add_error(e)
+              save_symlinks=True,
+              xdev=False):
+
+    # Issue top-level rewrite warnings.
+    for path in paths:
+        safe_path = _clean_up_path_for_archive(path)
+        if(safe_path != path):
+            log('bup: archiving "%s" as "%s"\n' % (path, safe_path))
+
+    start_dir = os.getcwd()
+    try:
+        for (p, st) in recursive_dirlist(paths, xdev=xdev):
+            dirlist_dir = os.getcwd()
+            os.chdir(start_dir)
+            safe_path = _clean_up_path_for_archive(p)
+            try:
+                m = from_path(p, archive_path=safe_path,
+                              save_symlinks=save_symlinks)
+            except MetadataAcquisitionError, e:
+                add_error(e)
 
-        if verbose:
-            print >> sys.stderr, m.path
-        m.write(output_file, include_path=write_paths)
-
-        if recurse and os.path.isdir(p):
-            for root, dirs, files in os.walk(p, onerror=add_error):
-                items = files + dirs
-                for sub_path in items:
-                    full_path = os.path.join(root, sub_path)
-                    safe_path = _clean_up_path_for_archive(full_path)
-                    try:
-                        m = from_path(full_path,
-                                      archive_path=safe_path,
-                                      save_symlinks=save_symlinks)
-                    except MetadataAcquisitionError, e:
-                        add_error(e)
-                    if verbose:
-                        print >> sys.stderr, m.path
-                    m.write(output_file, include_path=write_paths)
+            if verbose:
+                print >> sys.stderr, m.path
+            m.write(output_file, include_path=write_paths)
+            os.chdir(dirlist_dir)
+    finally:
+        os.chdir(start_dir)
 
 
 def _set_up_path(meta, create_symlinks=True):