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.
cute-signatures
Timo Teräs 2018-04-05 09:57:15 +03:00
parent 0dcbd933c8
commit 258519b1cd
1 changed files with 5 additions and 3 deletions

View File

@ -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);