diff options
author | Timo Teräs <timo.teras@iki.fi> | 2015-11-09 12:47:23 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2015-11-09 12:51:01 +0200 |
commit | cce4cff55310cddb2e2ec61d19b758e52a4e2c97 (patch) | |
tree | de2735305369fc75caee961485a6d44bc2782ce5 /src/url.c | |
parent | 7501f6012fc06ebfa8c6d8f928f38318267abe72 (diff) | |
download | apk-tools-cce4cff55310cddb2e2ec61d19b758e52a4e2c97.tar.gz apk-tools-cce4cff55310cddb2e2ec61d19b758e52a4e2c97.tar.bz2 apk-tools-cce4cff55310cddb2e2ec61d19b758e52a4e2c97.tar.xz apk-tools-cce4cff55310cddb2e2ec61d19b758e52a4e2c97.zip |
io, database: preserve [am]time for cached and fetched files
preserve [am]time for all packages and indexes. this fixes the caching
error that 'apk update' is after new index is generated, but before
the used mirror is synchronized. this caused local apkindex timestamp
to be newer than file in mirror, when in fact it was outdated index.
this also fixes fetched files to have build timestamp so that files
going to .iso or custom images have proper timestamps (rsync with
appropriate --modify-window now works)
Diffstat (limited to 'src/url.c')
-rw-r--r-- | src/url.c | 36 |
1 files changed, 27 insertions, 9 deletions
@@ -36,6 +36,7 @@ const char *apk_url_local_file(const char *url) struct apk_fetch_istream { struct apk_istream is; fetchIO *fetchIO; + struct url_stat urlstat; }; static int fetch_maperror(int ec) @@ -66,6 +67,16 @@ static int fetch_maperror(int ec) return map[ec]; } +static void fetch_get_meta(void *stream, struct apk_file_meta *meta) +{ + struct apk_fetch_istream *fis = container_of(stream, struct apk_fetch_istream, is); + + *meta = (struct apk_file_meta) { + .atime = fis->urlstat.atime, + .mtime = fis->urlstat.mtime, + }; +} + static ssize_t fetch_read(void *stream, void *ptr, size_t size) { struct apk_fetch_istream *fis = container_of(stream, struct apk_fetch_istream, is); @@ -95,28 +106,35 @@ static struct apk_istream *apk_istream_fetch(const char *url, time_t since) { struct apk_fetch_istream *fis; struct url *u; - fetchIO *io; + fetchIO *io = NULL; + int rc = -ENOMEM; u = fetchParseURL(url); - if (!u) return ERR_PTR(-ENOMEM); - u->last_modified = since; - io = fetchGet(u, "i"); - fetchFreeURL(u); - if (!io) return ERR_PTR(fetch_maperror(fetchLastErrCode)); - fis = malloc(sizeof(*fis)); - if (!fis) goto err; + if (!fis || !u) goto err; + + u->last_modified = since; + io = fetchXGet(u, &fis->urlstat, "i"); + if (!io) { + rc = fetch_maperror(fetchLastErrCode); + goto err; + } *fis = (struct apk_fetch_istream) { + .is.get_meta = fetch_get_meta, .is.read = fetch_read, .is.close = fetch_close, .fetchIO = io, + .urlstat = fis->urlstat, }; + fetchFreeURL(u); return &fis->is; err: + if (u) fetchFreeURL(u); if (io) fetchIO_close(io); - return ERR_PTR(-ENOMEM); + if (fis) free(fis); + return ERR_PTR(rc); } struct apk_istream *apk_istream_from_fd_url_if_modified(int atfd, const char *url, time_t since) |