1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
|