[packages/rpm-build-tools] Ignore dangling symlinks (there is no other cause for FileNotFoundError)

baggins baggins at pld-linux.org
Sun Apr 5 10:31:54 CEST 2020


commit 58c0fa8ad93b700fd614246bbd8270970e7b69f8
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Sun Apr 5 10:28:57 2020 +0200

    Ignore dangling symlinks (there is no other cause for FileNotFoundError)

 check-shebang.py | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/check-shebang.py b/check-shebang.py
index ecd0f60..0f66385 100755
--- a/check-shebang.py
+++ b/check-shebang.py
@@ -39,7 +39,10 @@ if args.buildroot:
             if fext in skip_files:
                 continue
             fpath = os.path.join(root, name)
-            rpm_build_root_files.append(hash(fpath))
+            try:
+                rpm_build_root_files.append(hash(fpath))
+            except FileNotFoundError:
+                pass
     print("%s: Caching done." % (sys.argv[0]))
 
 for root, dirs, files in os.walk(args.sourcedir):
@@ -49,24 +52,27 @@ for root, dirs, files in os.walk(args.sourcedir):
             continue
 
         fpath = os.path.join(root, name)
-        with open(fpath, 'rt', encoding='utf-8', errors='replace') as f:
-            try:
-                fline = f.read(128)
-                f = io.StringIO(fline)
-                shebang = f.readline()
-            except UnicodeDecodeError as e:
-                print("%s: skipping file `%s': %s" % (sys.argv[0], fpath, e), file=sys.stderr)
-                continue
-            if re.compile(r'^#!\s*/usr/bin/env python\s').match(shebang) \
-                    or re.compile(r'^#!\s*/usr/bin/env\s+python2\s').match(shebang) \
-                    or re.compile(r'^#!\s*/usr/bin/python\s').match(shebang):
-                rep['python2'].append(fpath)
-            elif re.compile(r'^#!\s*/usr/bin/env\s+python3\s').match(shebang):
-                rep['python3'].append(fpath)
-            elif re.compile(r'^#!\s*/usr/bin/env\s+perl\s').match(shebang):
-                rep['perl'].append(fpath)
-            elif re.compile(r'^#!\s*/usr/bin/env\s+ruby\s').match(shebang):
-                rep['ruby'].append(fpath)
+        try:
+            with open(fpath, 'rt', encoding='utf-8', errors='replace') as f:
+                try:
+                    fline = f.read(128)
+                    f = io.StringIO(fline)
+                    shebang = f.readline()
+                except UnicodeDecodeError as e:
+                    print("%s: skipping file `%s': %s" % (sys.argv[0], fpath, e), file=sys.stderr)
+                    continue
+                if re.compile(r'^#!\s*/usr/bin/env python\s').match(shebang) \
+                        or re.compile(r'^#!\s*/usr/bin/env\s+python2\s').match(shebang) \
+                        or re.compile(r'^#!\s*/usr/bin/python\s').match(shebang):
+                    rep['python2'].append(fpath)
+                elif re.compile(r'^#!\s*/usr/bin/env\s+python3\s').match(shebang):
+                    rep['python3'].append(fpath)
+                elif re.compile(r'^#!\s*/usr/bin/env\s+perl\s').match(shebang):
+                    rep['perl'].append(fpath)
+                elif re.compile(r'^#!\s*/usr/bin/env\s+ruby\s').match(shebang):
+                    rep['ruby'].append(fpath)
+        except FileNotFoundError:
+            pass
 
 def gf(cmd, files):
     newfiles = []
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/rpm-build-tools.git/commitdiff/58c0fa8ad93b700fd614246bbd8270970e7b69f8



More information about the pld-cvs-commit mailing list