summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2018-04-05 09:57:15 +0300
committerTimo Teräs <timo.teras@iki.fi>2018-04-05 09:57:17 +0300
commit258519b1cd32e285060fa4758c123b55ebfe3ef3 (patch)
tree388783ac7d90c5c494735b76492a5e0fd0e264e5 /src
parent0dcbd933c8d3d305395a99b7b1690a187ce5ec8c (diff)
downloadapk-tools-258519b1cd32e285060fa4758c123b55ebfe3ef3.tar.gz
apk-tools-258519b1cd32e285060fa4758c123b55ebfe3ef3.tar.bz2
apk-tools-258519b1cd32e285060fa4758c123b55ebfe3ef3.tar.xz
apk-tools-258519b1cd32e285060fa4758c123b55ebfe3ef3.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/database.c8
1 files 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);