aboutsummaryrefslogtreecommitdiffstats
path: root/main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch')
-rw-r--r--main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch34
1 files changed, 34 insertions, 0 deletions
diff --git a/main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch b/main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch
new file mode 100644
index 0000000000..263bc71955
--- /dev/null
+++ b/main/apk-tools/0002-db-fix-refreshing-index-if-time-is-zero.patch
@@ -0,0 +1,34 @@
+From 258519b1cd32e285060fa4758c123b55ebfe3ef3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
+Date: Thu, 5 Apr 2018 09:57:15 +0300
+Subject: [PATCH] db: fix refreshing index if time is zero
+
+During netboot on systems without RTC, time() will be near zero,
+and the index fill not exist. Thus the plain test of st.st_mtime
+against system time failed. Verify that fstatat() succeeds.
+---
+ src/database.c | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/src/database.c b/src/database.c
+index 3976d3d..db34ed3 100644
+--- a/src/database.c
++++ b/src/database.c
+@@ -634,9 +634,11 @@ int apk_cache_download(struct apk_database *db, struct apk_repository *repo,
+ r = apk_repo_format_real_url(db, repo, pkg, url, sizeof(url));
+ if (r < 0) return r;
+
+- if (!(apk_force & APK_FORCE_REFRESH))
+- (void) fstatat(db->cache_fd, cacheitem, &st, 0);
+- if (autoupdate && now - st.st_mtime <= db->cache_max_age) return -EALREADY;
++ if (autoupdate && !(apk_force & APK_FORCE_REFRESH)) {
++ if (fstatat(db->cache_fd, cacheitem, &st, 0) == 0 &&
++ now - st.st_mtime <= db->cache_max_age)
++ return -EALREADY;
++ }
+
+ apk_message("fetch %s", url);
+
+--
+2.16.3
+