45 lines
1.6 KiB
Diff
45 lines
1.6 KiB
Diff
|
From 3a072351314c3a3ec11650ad8efd2fc6ececf987 Mon Sep 17 00:00:00 2001
|
||
|
From: Dirk Mueller <dirk@dmllr.de>
|
||
|
Date: Sat, 4 Nov 2017 02:17:52 +0100
|
||
|
Subject: [PATCH] Properly handle the exception on missing files
|
||
|
|
||
|
Missing files raises a FileNotFoundError, not OSError. Also
|
||
|
simplify logic.
|
||
|
|
||
|
(cherry picked from commit d59bc2a1e2698040553c09610cb2befa1ef8d76a)
|
||
|
---
|
||
|
Pkg.py | 11 +++--------
|
||
|
1 file changed, 3 insertions(+), 8 deletions(-)
|
||
|
|
||
|
diff --git a/Pkg.py b/Pkg.py
|
||
|
index e257243..01d0289 100644
|
||
|
--- a/Pkg.py
|
||
|
+++ b/Pkg.py
|
||
|
@@ -714,20 +714,15 @@ class Pkg(AbstractPkg):
|
||
|
pkgfile.magic = "symbolic link to `%s'" % pkgfile.linkto
|
||
|
elif not pkgfile.size:
|
||
|
pkgfile.magic = 'empty'
|
||
|
- if not pkgfile.magic and _magic:
|
||
|
+ if (not pkgfile.magic and
|
||
|
+ not pkgfile.is_ghost and _magic):
|
||
|
# file() method evaluates every file twice with python2,
|
||
|
# use descriptor() method instead
|
||
|
try:
|
||
|
fd = os.open(pkgfile.path, os.O_RDONLY)
|
||
|
- except OSError:
|
||
|
- if not pkgfile.is_ghost:
|
||
|
- raise
|
||
|
- else:
|
||
|
pkgfile.magic = b2s(_magic.descriptor(fd))
|
||
|
- # libmagic up to 5.18 already closes the descriptor
|
||
|
- try:
|
||
|
os.close(fd)
|
||
|
- except OSError:
|
||
|
+ except FileNotFoundError:
|
||
|
pass
|
||
|
if pkgfile.magic is None:
|
||
|
pkgfile.magic = ''
|
||
|
--
|
||
|
2.17.0
|
||
|
|