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

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