1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-24 07:01:59 +00:00

use new OS and IO exception hierarchy of py 3.3

This commit is contained in:
Thomas Waldmann 2015-12-15 00:09:36 +01:00
parent 19729d3983
commit a6f9c29dfe
4 changed files with 17 additions and 25 deletions

View file

@ -137,14 +137,14 @@ def create_inner(archive, cache):
try: try:
st = os.stat(get_cache_dir()) st = os.stat(get_cache_dir())
skip_inodes.add((st.st_ino, st.st_dev)) skip_inodes.add((st.st_ino, st.st_dev))
except IOError: except OSError:
pass pass
# Add local repository dir to inode_skip list # Add local repository dir to inode_skip list
if not args.location.host: if not args.location.host:
try: try:
st = os.stat(args.location.path) st = os.stat(args.location.path)
skip_inodes.add((st.st_ino, st.st_dev)) skip_inodes.add((st.st_ino, st.st_dev))
except IOError: except OSError:
pass pass
for path in args.paths: for path in args.paths:
if path == '-': # stdin if path == '-': # stdin
@ -152,7 +152,7 @@ def create_inner(archive, cache):
if not dry_run: if not dry_run:
try: try:
status = archive.process_stdin(path, cache) status = archive.process_stdin(path, cache)
except IOError as e: except OSError as e:
status = 'E' status = 'E'
self.print_warning('%s: %s', path, e) self.print_warning('%s: %s', path, e)
else: else:
@ -229,7 +229,7 @@ def _process(self, archive, cache, matcher, exclude_caches, exclude_if_present,
if not dry_run: if not dry_run:
try: try:
status = archive.process_file(path, st, cache) status = archive.process_file(path, st, cache)
except IOError as e: except OSError as e:
status = 'E' status = 'E'
self.print_warning('%s: %s', path, e) self.print_warning('%s: %s', path, e)
elif stat.S_ISDIR(st.st_mode): elif stat.S_ISDIR(st.st_mode):
@ -326,7 +326,7 @@ def do_extract(self, args):
archive.extract_item(item, restore_attrs=False) archive.extract_item(item, restore_attrs=False)
else: else:
archive.extract_item(item, stdout=stdout, sparse=sparse) archive.extract_item(item, stdout=stdout, sparse=sparse)
except IOError as e: except OSError as e:
self.print_warning('%s: %s', remove_surrogates(orig_path), e) self.print_warning('%s: %s', remove_surrogates(orig_path), e)
if not args.dry_run: if not args.dry_run:

View file

@ -132,14 +132,13 @@ def acquire(self, timeout=None, sleep=None):
while True: while True:
try: try:
os.mkdir(self.path) os.mkdir(self.path)
except FileExistsError: # already locked
if self.by_me():
return self
if timer.timed_out_or_sleep():
raise LockTimeout(self.path)
except OSError as err: except OSError as err:
if err.errno == errno.EEXIST: # already locked raise LockFailed(self.path, str(err))
if self.by_me():
return self
if timer.timed_out_or_sleep():
raise LockTimeout(self.path)
else:
raise LockFailed(self.path, str(err))
else: else:
with open(self.unique_name, "wb"): with open(self.unique_name, "wb"):
pass pass
@ -181,12 +180,8 @@ def load(self):
try: try:
with open(self.path) as f: with open(self.path) as f:
data = json.load(f) data = json.load(f)
except IOError as err: except (FileNotFoundError, ValueError):
if err.errno != errno.ENOENT: # no or corrupt/empty roster file?
raise
data = {}
except ValueError:
# corrupt/empty roster file?
data = {} data = {}
return data return data
@ -197,9 +192,8 @@ def save(self, data):
def remove(self): def remove(self):
try: try:
os.unlink(self.path) os.unlink(self.path)
except OSError as e: except FileNotFoundError:
if e.errno != errno.ENOENT: pass
raise
def get(self, key): def get(self, key):
roster = self.load() roster = self.load()

View file

@ -567,7 +567,7 @@ def delete_segment(self, segment):
del self.fds[segment] del self.fds[segment]
try: try:
os.unlink(self.segment_filename(segment)) os.unlink(self.segment_filename(segment))
except OSError: except FileNotFoundError:
pass pass
def segment_exists(self, segment): def segment_exists(self, segment):

View file

@ -70,9 +70,7 @@ def exec_cmd(*args, archiver=None, fork=False, exe=None, **kw):
try: try:
exec_cmd('help', exe='borg.exe', fork=True) exec_cmd('help', exe='borg.exe', fork=True)
BORG_EXES = ['python', 'binary', ] BORG_EXES = ['python', 'binary', ]
except (IOError, OSError) as err: except FileNotFoundError:
if err.errno != errno.ENOENT:
raise
BORG_EXES = ['python', ] BORG_EXES = ['python', ]