diff --git a/darc/archiver.py b/darc/archiver.py index 3af740c8c..d3c0f4487 100644 --- a/darc/archiver.py +++ b/darc/archiver.py @@ -9,7 +9,7 @@ from .cache import Cache from .keychain import Keychain from .helpers import location_validator, format_file_size, format_time,\ - format_file_mode, walk_path, IncludePattern, ExcludePattern, exclude_path + format_file_mode, IncludePattern, ExcludePattern, exclude_path from .remote import StoreServer, RemoteStore class Archiver(object): @@ -74,27 +74,42 @@ def do_create(self, args): except IOError: pass for path in args.paths: - for path, st in walk_path(unicode(path)): - if exclude_path(path, args.patterns): - continue - self.print_verbose(path) - if stat.S_ISDIR(st.st_mode): - archive.process_dir(path, st) - elif stat.S_ISLNK(st.st_mode): - archive.process_symlink(path, st) - elif stat.S_ISFIFO(st.st_mode): - archive.process_fifo(path, st) - elif stat.S_ISREG(st.st_mode): - try: - archive.process_file(path, st, cache) - except IOError, e: - self.print_error('%s: %s', path, e) - else: - self.print_error('Unknown file type: %s', path) + self._process(archive, cache, args.patterns, unicode(path)) archive.save(args.archive.archive) cache.save() return self.exit_code + def _process(self, archive, cache, patterns, path): + if exclude_path(path, patterns): + return + try: + st = os.lstat(path) + except OSError, e: + self.print_error('%s: %s', path, e) + return + self.print_verbose(path) + if stat.S_ISDIR(st.st_mode): + archive.process_dir(path, st) + try: + entries = os.listdir(path) + except OSError, e: + self.print_error('%s: %s', path, e) + else: + for filename in entries: + self._process(archive, cache, patterns, + os.path.join(path, filename)) + elif stat.S_ISLNK(st.st_mode): + archive.process_symlink(path, st) + elif stat.S_ISFIFO(st.st_mode): + archive.process_fifo(path, st) + elif stat.S_ISREG(st.st_mode): + try: + archive.process_file(path, st, cache) + except IOError, e: + self.print_error('%s: %s', path, e) + else: + self.print_error('Unknown file type: %s', path) + def do_extract(self, args): store = self.open_store(args.archive) keychain = Keychain(args.keychain)