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:
parent
2a631bb3e6
commit
231c06f0d5
1 changed files with 33 additions and 18 deletions
|
@ -9,7 +9,7 @@
|
||||||
from .cache import Cache
|
from .cache import Cache
|
||||||
from .keychain import Keychain
|
from .keychain import Keychain
|
||||||
from .helpers import location_validator, format_file_size, format_time,\
|
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
|
from .remote import StoreServer, RemoteStore
|
||||||
|
|
||||||
class Archiver(object):
|
class Archiver(object):
|
||||||
|
@ -74,27 +74,42 @@ def do_create(self, args):
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
for path in args.paths:
|
for path in args.paths:
|
||||||
for path, st in walk_path(unicode(path)):
|
self._process(archive, cache, args.patterns, 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)
|
|
||||||
archive.save(args.archive.archive)
|
archive.save(args.archive.archive)
|
||||||
cache.save()
|
cache.save()
|
||||||
return self.exit_code
|
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):
|
def do_extract(self, args):
|
||||||
store = self.open_store(args.archive)
|
store = self.open_store(args.archive)
|
||||||
keychain = Keychain(args.keychain)
|
keychain = Keychain(args.keychain)
|
||||||
|
|
Loading…
Reference in a new issue