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

View file

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

View file

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

View file

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