[packages/rpm-build-tools] Use file hashes instead of file names (in case of file renames).

arekm arekm at pld-linux.org
Mon Dec 23 10:17:59 CET 2019


commit ba289b0bfb98feab124e6aa6984c3731b872037a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Dec 23 10:17:52 2019 +0100

    Use file hashes instead of file names (in case of file renames).

 check-shebang.py | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)
---
diff --git a/check-shebang.py b/check-shebang.py
index 4408e3f..6de4fc1 100755
--- a/check-shebang.py
+++ b/check-shebang.py
@@ -3,6 +3,7 @@
 # thisscript.py --buildroot=~/tmp/somepackage ~/rpm/BUILD/somepackage/
 
 import argparse
+import hashlib
 import io
 import os
 import re
@@ -21,15 +22,23 @@ rep = {
 
 skip_files = [".h", ".c", ".cc", ".gif", ".png", ".jpg", ".ko", ".gz", ".o"]
 
+def hash(fname):
+    hash_alg = hashlib.sha256()
+    with open(fname, "rb") as f:
+        for chunk in iter(lambda: f.read(4096), b""):
+            hash_alg.update(chunk)
+    return hash_alg.hexdigest()
+
+rpm_build_root_files = []
 if args.buildroot:
     print("%s: Caching `%s' files..." % (sys.argv[0], args.buildroot))
-    rpm_build_root_files = []
     for root, dirs, files in os.walk(args.buildroot):
         for name in files:
             fname, fext = os.path.splitext(name)
             if fext in skip_files:
                 continue
-            rpm_build_root_files.append(fname)
+            fpath = os.path.join(root, name)
+            rpm_build_root_files.append(hash(fpath))
     print("%s: Caching done." % (sys.argv[0]))
 
 for root, dirs, files in os.walk(args.sourcedir):
@@ -56,12 +65,15 @@ for root, dirs, files in os.walk(args.sourcedir):
             elif re.compile(r'^#!/usr/bin/env perl\s').match(shebang):
                 rep['perl'].append(fpath)
 
-def gf(files):
+def gf(cmd, files):
     newfiles = []
     for f in files:
-        if not rpm_build_root_files or os.path.basename(f) in rpm_build_root_files:
+        if not rpm_build_root_files or hash(f) in rpm_build_root_files:
             newfiles.append(f)
     newfiles.sort()
+    if not newfiles:
+        return
+    print(cmd)
     for i in range(0, len(newfiles) - 1):
         print("\t%s \\\n" % os.path.relpath(newfiles[i], start=args.sourcedir), end='')
     print("\t%s\n" % os.path.relpath(newfiles[len(newfiles) - 1], start=args.sourcedir))
@@ -72,14 +84,7 @@ if args.buildroot:
     print("--root=%s " % args.buildroot, end='')
 print("%s\n" % args.sourcedir)
 
-if rep['python2']:
-    print("sed -i -e '1s,#!/usr/bin/env python2,%{__python},' -e '1s,#!/usr/bin/env python,%{__python},' -e '1s,#!/usr/bin/python,%{__python},' \\")
-    gf(rep['python2'])
-
-if rep['python3']:
-    print("sed -i -e '1s,#!/usr/bin/env python3,%{__python3},' \\")
-    gf(rep['python3'])
-
-if rep['perl']:
-    print("sed -i -e '1s,#!/usr/bin/env perl,%{__perl},' \\")
-    gf(rep['perl'])
+gf("sed -i -e '1s,#!/usr/bin/env python2,%{__python},' -e '1s,#!/usr/bin/env python,%{__python},' -e '1s,#!/usr/bin/python,%{__python},' \\",
+   rep['python2'])
+gf("sed -i -e '1s,#!/usr/bin/env python3,%{__python3},' \\", rep['python3'])
+gf("sed -i -e '1s,#!/usr/bin/env perl,%{__perl},' \\", rep['perl'])
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list