1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-12 09:30:27 +00:00

Move walk_path logic into archiver.py for better error handling

This commit is contained in:
Jonas Borgström 2010-11-23 12:50:09 +01:00
parent 2a631bb3e6
commit 231c06f0d5

View file

@ -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)