diff options
author | Timo Teräs <timo.teras@iki.fi> | 2018-01-04 09:46:03 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2018-01-04 10:56:09 +0200 |
commit | 8a28c6d0d4f81406c67e76b2bcdbe491aa734717 (patch) | |
tree | 148555889d66a69cdcd979ad77f1ba728b747f53 /src/apk.c | |
parent | 2da67940d50865d206f6a79165ce7b3de5a90de3 (diff) | |
download | apk-tools-8a28c6d0d4f81406c67e76b2bcdbe491aa734717.tar.gz apk-tools-8a28c6d0d4f81406c67e76b2bcdbe491aa734717.tar.bz2 apk-tools-8a28c6d0d4f81406c67e76b2bcdbe491aa734717.tar.xz apk-tools-8a28c6d0d4f81406c67e76b2bcdbe491aa734717.zip |
enable automatic update of indexes controlled by --cache-max-age
This modifies apk cache for indexes to be automatically refreshed
periodically without explicit 'update' or '--update-cache' usage.
The default is to do if-modified-since request if the local copy
is older than 4 hours. This age can be changed with --cache-max-age.
Using --update-cache will change this age to 60 seconds to make
sure the cached copy is relatively new. The small age is in order
to try to avoid downloading indexes second time when apk-tools is
upgraded and apk re-execs after self-upgrade.
Accordingly using explicitly 'apk update' will now enforce
--force-refresh and request the very latest index by requesting
any potential http proxy to do refresh too.
Diffstat (limited to 'src/apk.c')
-rw-r--r-- | src/apk.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -120,9 +120,6 @@ static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt case 'i': apk_flags |= APK_INTERACTIVE; break; - case 'U': - apk_flags |= APK_UPDATE_CACHE; - break; case 0x101: apk_flags |= APK_PROGRESS; break; @@ -153,6 +150,14 @@ static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt case 0x116: dbopts->cache_dir = optarg; break; + case 'U': + /* Make it one minute, to avoid updating indexes twice + * when doing self-upgrade's re-exec */ + dbopts->cache_max_age = 60; + break; + case 0x119: + dbopts->cache_max_age = atoi(optarg) * 60; + break; case 0x112: dbopts->arch = optarg; break; @@ -193,7 +198,7 @@ static const struct apk_option options_global[] = { { 0x121, "force-old-apk", "Continue even if packages use unsupported features" }, { 0x120, "force-overwrite", "Overwrite files in other packages" }, { 0x123, "force-refresh", "Do not use cached files (local or from proxy)" }, - { 'U', "update-cache", "Update the repository cache" }, + { 'U', "update-cache", "Alias for --cache-max-age 60" }, { 0x101, "progress", "Show a progress bar" }, { 0x10f, "progress-fd", "Write progress to fd", required_argument, "FD" }, { 0x110, "no-progress", "Disable progress bar even for TTYs" }, @@ -211,6 +216,8 @@ static const struct apk_option options_global[] = { { 0x115, "no-cache", "Do not use any local cache path" }, { 0x116, "cache-dir", "Override cache directory", required_argument, "CACHEDIR" }, + { 0x119, "cache-max-age", "Maximum AGE (in minutes) for index in cache before refresh", + required_argument, "AGE" }, { 0x112, "arch", "Use architecture with --root", required_argument, "ARCH" }, { 0x114, "print-arch", "Print default arch and exit" }, @@ -528,6 +535,7 @@ int main(int argc, char **argv) ctx = calloc(1, applet->context_size); dbopts.open_flags = applet->open_flags; apk_flags |= applet->forced_flags; + apk_force |= applet->forced_force; } for (opt = all_options, sopt = short_options; opt->name != NULL; opt++) { if (opt->flag == NULL && |