summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-04-29 06:37:40 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-04-29 06:37:40 -0400
commit948e0e109a6c226c140db7be035b5c65338bc1c7 (patch)
treeb7b964ac820c1c965ed0afa06c63259bb9d960fe
parentff83e8b5238aaf6b194d4215df8d8e4850f238de (diff)
db-check-package-libraries: Make it more robust.
First, to ease debugging, put some information in tmpdir filenames. Then, to avoid issues with reading files that are mode unreadable, or stat()ing them in unexecutable directories, add two `find` commands that reset bad permissions to 755/644. Then, skip over symlinks. Beside absolute links being broken in our implementation, it also means that links to files in different packages are broken. This leads to an exception being thrown, as the file can't be open()ed. Finally, skip over non-regular-file files. One package I tried contained a named FIFO, which caused it to hang on open().
-rwxr-xr-xdb-check-package-libraries16
1 files changed, 13 insertions, 3 deletions
diff --git a/db-check-package-libraries b/db-check-package-libraries
index 612fc4f..e24b58e 100755
--- a/db-check-package-libraries
+++ b/db-check-package-libraries
@@ -89,9 +89,17 @@ def add_package(con, package):
# Extract to a temporary directory. This could be done more
# efficiently, since there is no need to store more than one file
# at once.
- with tempfile.TemporaryDirectory() as temp:
- tar = subprocess.Popen(("bsdtar", "xf", package, "-C", temp))
- tar.communicate()
+ print("adding package:", package)
+ with tempfile.TemporaryDirectory(None, "db-check-package-libraries."+os.path.basename(package)+".") as temp:
+ subprocess.Popen(("bsdtar", "xf", package, "-C", temp)).communicate()
+ subprocess.Popen(('find', temp,
+ '-type', 'd',
+ '(', '-not', '-readable', '-o', '-not', '-executable', ')',
+ '-exec', 'chmod', '755', '--', '{}', ';')).communicate()
+ subprocess.Popen(('find', temp,
+ '-type', 'f',
+ '-not', '-readable',
+ '-exec', 'chmod', '644', '--', '{}', ';')).communicate()
with open(os.path.join(temp, ".PKGINFO")) as pkginfo:
for line in pkginfo:
if line.startswith("pkgname ="):
@@ -106,6 +114,8 @@ def add_package(con, package):
assert dirnames is not None # unused, avoid pylint warning
for file_name in filenames:
path = os.path.join(dirname, file_name)
+ if os.path.islink(path) or not os.path.isfile(path):
+ continue
with open(path, "rb") as file_object:
if file_object.read(4) != b"\177ELF":
continue