summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemato/find_top_level.py6
-rw-r--r--gemato/openpgp.py4
-rw-r--r--gemato/recursiveloader.py32
-rw-r--r--gemato/verify.py8
-rw-r--r--tests/test_find_top_level.py2
-rwxr-xr-xutils/gen_fast_manifest.py4
6 files changed, 24 insertions, 32 deletions
diff --git a/gemato/find_top_level.py b/gemato/find_top_level.py
index d049f17..5c71ddd 100644
--- a/gemato/find_top_level.py
+++ b/gemato/find_top_level.py
@@ -3,7 +3,6 @@
# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
-import errno
import os
import os.path
@@ -64,9 +63,8 @@ def find_top_level_manifest(path='.', allow_xdev=True, allow_compressed=False):
return last_found
m.load(f, verify_openpgp=False)
- except IOError as e:
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
+ pass
else:
# check if the initial path is ignored
relpath = os.path.relpath(path, cur_path)
diff --git a/gemato/openpgp.py b/gemato/openpgp.py
index b1100c1..76b7de8 100644
--- a/gemato/openpgp.py
+++ b/gemato/openpgp.py
@@ -195,9 +195,7 @@ class OpenPGPSystemEnvironment:
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env)
- except OSError as e:
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
raise OpenPGPNoImplementation()
out, err = p.communicate(stdin)
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py
index 9f6d360..8c994fb 100644
--- a/gemato/recursiveloader.py
+++ b/gemato/recursiveloader.py
@@ -3,7 +3,6 @@
# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
-import errno
import os.path
from gemato.compression import (
@@ -323,22 +322,21 @@ class ManifestRecursiveLoader:
try:
m, st = self.manifest_loader.verify_and_load(
relpath, verify_entry)
- except IOError as err:
- if err.errno == errno.ENOENT and allow_create:
- m = ManifestFile()
- path = os.path.join(self.root_directory, relpath)
- st = os.stat(os.path.dirname(path))
- # trigger saving
- self.updated_manifests.add(relpath)
-
- # add initial IGNORE entries to top-level Manifest
- if relpath == 'Manifest':
- for ip in (self.profile
- .get_ignore_paths_for_new_manifest('')):
- ie = ManifestEntryIGNORE(ip)
- m.entries.append(ie)
- else:
- raise err
+ except FileNotFoundError:
+ if not allow_create:
+ raise
+ m = ManifestFile()
+ path = os.path.join(self.root_directory, relpath)
+ st = os.stat(os.path.dirname(path))
+ # trigger saving
+ self.updated_manifests.add(relpath)
+
+ # add initial IGNORE entries to top-level Manifest
+ if relpath == 'Manifest':
+ for ip in (self.profile
+ .get_ignore_paths_for_new_manifest('')):
+ ie = ManifestEntryIGNORE(ip)
+ m.entries.append(ie)
if store_dev:
self.manifest_device = st.st_dev
diff --git a/gemato/verify.py b/gemato/verify.py
index 720decc..64d367e 100644
--- a/gemato/verify.py
+++ b/gemato/verify.py
@@ -40,11 +40,11 @@ def get_file_metadata(path, hashes):
try:
# we want O_NONBLOCK to avoid blocking when opening pipes
fd = os.open(path, os.O_RDONLY | os.O_NONBLOCK)
+ except FileNotFoundError:
+ exists = False
+ opened = False
except OSError as err:
- if err.errno == errno.ENOENT:
- exists = False
- opened = False
- elif err.errno in (errno.ENXIO, errno.EOPNOTSUPP):
+ if err.errno in (errno.ENXIO, errno.EOPNOTSUPP):
# ENXIO = unconnected device or socket
# EOPNOTSUPP = opening UNIX socket on FreeBSD
exists = True
diff --git a/tests/test_find_top_level.py b/tests/test_find_top_level.py
index c4df873..47b3f1e 100644
--- a/tests/test_find_top_level.py
+++ b/tests/test_find_top_level.py
@@ -62,7 +62,7 @@ def test_unreadable_manifest(tmp_path):
"""Test failure when one of Manifest files is not readable"""
with open(tmp_path / 'Manifest', 'w') as f:
os.fchmod(f.fileno(), 0)
- with pytest.raises(IOError):
+ with pytest.raises(PermissionError):
find_top_level_manifest(tmp_path)
diff --git a/utils/gen_fast_manifest.py b/utils/gen_fast_manifest.py
index f9eed6c..d7c8c51 100755
--- a/utils/gen_fast_manifest.py
+++ b/utils/gen_fast_manifest.py
@@ -89,9 +89,7 @@ def gen_manifest(top_dir):
if l.startswith(b'DIST') or l.startswith(b'IGNORE'):
manifest_entries.append(l.rstrip())
had_manifest = True
- except IOError as e:
- if e.errno != errno.ENOENT:
- raise
+ except FileNotFoundError:
had_manifest = False
# generate local file entries