Blame SOURCES/no-floats-in-sources.patch

7f8145
From 7b0db90c76c6b0de6a4d481e63450e8f0d1a1d9d Mon Sep 17 00:00:00 2001
7f8145
From: =?UTF-8?q?Ond=C5=99ej=20Budai?= <obudai@redhat.com>
7f8145
Date: Thu, 25 Jun 2020 09:56:30 +0200
7f8145
Subject: [PATCH] sources/files: do not pass floats to --max-time
7f8145
7f8145
curl uses strtod from the C standard library to convert the --max-time's value
7f8145
from string to double. However, this is what strtod expects:
7f8145
7f8145
nonempty sequence of decimal digits optionally containing decimal-point
7f8145
character (as determined by the current C locale)
7f8145
7f8145
Yeah, unfortunately, the decimal-point character is determined by the current
7f8145
C locale. For example, Czech and German locale uses a comma as the
7f8145
decimal-point character.
7f8145
7f8145
For reasons I don't fully understand, Python thinks it's running on en_US
7f8145
locale, even though LC_NUMERIC is set to cs_CZ, so it uses a full stop as the
7f8145
decimal-point character when converting float to string. However, as written
7f8145
before, curl fails to parse this because it expects comma.
7f8145
7f8145
The fix I chose is simple: Use math.ceil, so only an integer can be passed to
7f8145
curl. Why ceil? Because --max-time == 0 sounds fishy. math.ceil should return
7f8145
an integer (and it does in Python 3.8) but the documentation is not 100% clear
7f8145
on this topic, so let's be paranoid and also convert it to int after the
7f8145
ceiling.
7f8145
---
7f8145
 sources/org.osbuild.files | 3 ++-
7f8145
 1 file changed, 2 insertions(+), 1 deletion(-)
7f8145
7f8145
diff --git a/sources/org.osbuild.files b/sources/org.osbuild.files
7f8145
index 42ff6ca..13ce9b8 100755
7f8145
--- a/sources/org.osbuild.files
7f8145
+++ b/sources/org.osbuild.files
7f8145
@@ -17,6 +17,7 @@ import concurrent.futures
7f8145
 import glob
7f8145
 import itertools
7f8145
 import json
7f8145
+import math
7f8145
 import os
7f8145
 import subprocess
7f8145
 import sys
7f8145
@@ -102,7 +103,7 @@ def fetch(url, checksum, directory):
7f8145
             curl_command = [
7f8145
                 "curl",
7f8145
                 "--silent",
7f8145
-                "--max-time", f"{300 - elapsed_time}",
7f8145
+                "--max-time", f"{int(math.ceil(300 - elapsed_time))}",
7f8145
                 "--connect-timeout", "60",
7f8145
                 "--fail",
7f8145
                 "--location",
7f8145
-- 
7f8145
2.26.2
7f8145