Merge bitcoin/bitcoin#30703: test: Avoid duplicate curl call in get_previous_releases.py
Some checks are pending
CI / test each commit (push) Waiting to run
CI / macOS 13 native, x86_64, no depends, sqlite only, gui (push) Waiting to run
CI / Win64 native, VS 2022 (push) Waiting to run
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run

fa5aeab3cb test: Avoid duplicate curl call in get_previous_releases.py (MarcoFalke)

Pull request description:

  Seems odd having to translate `404` to "Binary tag was not found". Also, it seems odd to write a for-loop over a list with one item.

  Fix both issues by just using a single call to `curl --fail ...`.

  Can be tested with: `test/get_previous_releases.py -b v99.99.99`

  Before:

  ```
  Releases directory: releases
  Fetching: https://bitcoincore.org/bin/bitcoin-core-99.99.99/bitcoin-99.99.99-x86_64-linux-gnu.tar.gz
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0  286k    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  Binary tag was not found
  ```

  After:

  ```
  Releases directory: releases
  Fetching: https://bitcoincore.org/bin/bitcoin-core-99.99.99/bitcoin-99.99.99-x86_64-linux-gnu.tar.gz
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
    0  286k    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
  curl: (22) The requested URL returned error: 404

ACKs for top commit:
  fanquake:
    ACK fa5aeab3cb
  brunoerg:
    utACK fa5aeab3cb
  tdb3:
    tested ACK fa5aeab3cb

Tree-SHA512: d5d31e0bccdd9de9b4a8ecf2e69348f4e8cee773050c8259b61db1ce5de73f6fbfffbe8c4d2571f7bef2de29cb42fd244573deebfbec614e487e76ef41681b9c
This commit is contained in:
merge-script 2024-08-24 16:24:23 +01:00
commit d54fbc85c4
No known key found for this signature in database
GPG key ID: 2EEB9F5CC09526C1

View file

@ -133,20 +133,9 @@ def download_binary(tag, args) -> int:
print('Fetching: {tarballUrl}'.format(tarballUrl=tarballUrl))
header, status = subprocess.Popen(
['curl', '--head', tarballUrl], stdout=subprocess.PIPE).communicate()
if re.search("404 Not Found", header.decode("utf-8")):
print("Binary tag was not found")
return 1
curlCmds = [
['curl', '--remote-name', tarballUrl]
]
for cmd in curlCmds:
ret = subprocess.run(cmd).returncode
if ret:
return ret
ret = subprocess.run(['curl', '--fail', '--remote-name', tarballUrl]).returncode
if ret:
return ret
hasher = hashlib.sha256()
with open(tarball, "rb") as afile: