Skip to contentSkip to conversation

utils/check-package: add a check for the separation in the hash files

PATCH New Heiko Thiery 2 participants 3 messages Feb 4, 2020 – Feb 5, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/check-package: add a check for the separation in the hash files

The seperation of the fields in the hash file should be 2 spaces for consitency.

Add some extra infos about that in the "adding-packages-directory" part of the manual.

---
 docs/manual/adding-packages-directory.txt | 6 ++++--
 utils/checkpackagelib/lib_hash.py         | 7 ++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
docs/manual/adding-packages-directory.txt +4 -2
index 1c8b9f96b5..2c1a7d8776 100644
@@ -461,7 +461,8 @@ The hashes stored in that file are used to validate the integrity of the
 downloaded files and of the license files.
 
 The format of this file is one line for each file for which to check the
-hash, each line being space-separated, with these three fields:
+hash. For every file to check the three fields (hash type, hash, filename)
+has to be in that file separated by 2 spaces.
 
 * the type of hash, one of:
 ** +md5+, +sha1+, +sha224+, +sha256+, +sha384+, +sha512+, +none+
@@ -502,7 +503,8 @@ create the hash file in a subdirectory +<packageversion>+ of that package
 
 .Note
 The number of spaces does not matter, so one can use spaces (or tabs) to
-properly align the different fields.
+properly align the different fields. Nethertheless new packages has to be
+separated by 2 spaces.
 
 The +none+ hash type is reserved to those archives downloaded from a
 repository, like a 'git clone', a 'subversion checkout'...
utils/checkpackagelib/lib_hash.py +6 -1
index 3e381119a5..618ae5f679 100644
@@ -40,7 +40,7 @@ class HashType(_CheckFunction):
         if len(fields) < 2:
             return
 
-        htype, hexa = fields[:2]
+        htype, hexa, filename = fields[:3]
         if htype == "none":
             return
         if htype not in self.len_of_hash.keys():
@@ -53,3 +53,8 @@ class HashType(_CheckFunction):
                     .format(self.filename, lineno, self.url_to_manual),
                     text,
                     "expected {} hex digits".format(self.len_of_hash[htype])]
+
+        if not re.match("^{}  {}  {}.*$".format(htype, hexa, filename), text):
+            return ["{}:{}: separation does not match expectation ({}#adding-packages-hash)"
+                    .format(self.filename, lineno, self.url_to_manual),
+                    text]
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/1 utils/check-package: add a check for the separation in the hash files

Heiko, All,

On 2020-02-04 11:38 +0100, Heiko Thiery spake thusly:

Quoted 2 lines

The seperation of the fields in the hash file should be 2 spaces for consitency.

The script now throwsa traceback:

    $ make check-package
    [lots of output...]
    Traceback (most recent call last):
      File "./utils/check-package", line 194, in <module>
        __main__()
      File "./utils/check-package", line 177, in __main__
        nwarnings, nlines = check_file_using_lib(fname)
      File "./utils/check-package", line 146, in check_file_using_lib
        nwarnings += print_warnings(cf.check_line(lineno + 1, text))
      File "/home/ymorin/dev/buildroot/buildroot/utils/checkpackagelib/lib_hash.py", line 57, in check_line
        if not re.match("^{}  {}  {}.*$".format(htype, hexa, filename), text):
      File "/usr/lib/python2.7/re.py", line 141, in match
        return _compile(pattern, flags).match(string)
      File "/usr/lib/python2.7/re.py", line 251, in _compile
        raise error, v # invalid expression
    sre_constants.error: multiple repeat
    make: *** [Makefile:1185: check-package] Error 1

Care to have a look at it?

In the meantime...

Quoted 2 lines

Add some extra infos about that in the "adding-packages-directory" part of the manual.

I've reworded that manual part, updated the following example while at it, and applied to master. Thanks! :-)

Regards,
Yann E. MORIN.

Quoted 55 lines
---
 docs/manual/adding-packages-directory.txt | 6 ++++--
 utils/checkpackagelib/lib_hash.py         | 7 ++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
docs/manual/adding-packages-directory.txt +4 -2
index 1c8b9f96b5..2c1a7d8776 100644
@@ -461,7 +461,8 @@ The hashes stored in that file are used to validate the integrity of the
 downloaded files and of the license files.
 
 The format of this file is one line for each file for which to check the
-hash, each line being space-separated, with these three fields:
+hash. For every file to check the three fields (hash type, hash, filename)
+has to be in that file separated by 2 spaces.
 
 * the type of hash, one of:
 ** +md5+, +sha1+, +sha224+, +sha256+, +sha384+, +sha512+, +none+
@@ -502,7 +503,8 @@ create the hash file in a subdirectory +<packageversion>+ of that package
 
 .Note
 The number of spaces does not matter, so one can use spaces (or tabs) to
-properly align the different fields.
+properly align the different fields. Nethertheless new packages has to be
+separated by 2 spaces.
 
 The +none+ hash type is reserved to those archives downloaded from a
 repository, like a 'git clone', a 'subversion checkout'...
utils/checkpackagelib/lib_hash.py +6 -1
index 3e381119a5..618ae5f679 100644
@@ -40,7 +40,7 @@ class HashType(_CheckFunction):
         if len(fields) < 2:
             return
 
-        htype, hexa = fields[:2]
+        htype, hexa, filename = fields[:3]
         if htype == "none":
             return
         if htype not in self.len_of_hash.keys():
@@ -53,3 +53,8 @@ class HashType(_CheckFunction):
                     .format(self.filename, lineno, self.url_to_manual),
                     text,
                     "expected {} hex digits".format(self.len_of_hash[htype])]
+
+        if not re.match("^{}  {}  {}.*$".format(htype, hexa, filename), text):
+            return ["{}:{}: separation does not match expectation ({}#adding-packages-hash)"
+                    .format(self.filename, lineno, self.url_to_manual),
+                    text]
Signature · 1 line
2.20.1
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH 1/1 utils/check-package: add a check for the separation in the hash files

Yann, All,

Quoted 20 lines

The script now throwsa traceback:

    $ make check-package
    [lots of output...]
    Traceback (most recent call last):
      File "./utils/check-package", line 194, in <module>
        __main__()
      File "./utils/check-package", line 177, in __main__
        nwarnings, nlines = check_file_using_lib(fname)
      File "./utils/check-package", line 146, in check_file_using_lib
        nwarnings += print_warnings(cf.check_line(lineno + 1, text))
      File "/home/ymorin/dev/buildroot/buildroot/utils/checkpackagelib/lib_hash.py", line 57, in check_line
        if not re.match("^{}  {}  {}.*$".format(htype, hexa, filename), text):
      File "/usr/lib/python2.7/re.py", line 141, in match
        return _compile(pattern, flags).match(string)
      File "/usr/lib/python2.7/re.py", line 251, in _compile
        raise error, v # invalid expression
    sre_constants.error: multiple repeat
    make: *** [Makefile:1185: check-package] Error 1
Quoted 1 line

Care to have a look at it?

Yes I see it .. the string has to be escaped .. I will prepare that and send a patch.

--
Heiko