implement --update-cache option

This will update the repository cache upon db_open.
cute-signatures
Natanael Copa 2009-07-07 11:12:24 +02:00
parent f1125dfcde
commit 080fa825dd
4 changed files with 12 additions and 2 deletions

View File

@ -41,6 +41,7 @@ static struct apk_option generic_options[] = {
{ 'v', "verbose", "Print more information" }, { 'v', "verbose", "Print more information" },
{ 'V', "version", "Print program version and exit" }, { 'V', "version", "Print program version and exit" },
{ 'f', "force", "Do what was asked even if it looks dangerous" }, { 'f', "force", "Do what was asked even if it looks dangerous" },
{ 'U', "update-cache", "Update the repository cache" },
{ 0x101, "progress", "Show a progress bar" }, { 0x101, "progress", "Show a progress bar" },
{ 0x102, "clean-protected", "Do not create .apk-new files to " { 0x102, "clean-protected", "Do not create .apk-new files to "
"configuration dirs" }, "configuration dirs" },
@ -324,6 +325,9 @@ int main(int argc, char **argv)
case 'f': case 'f':
apk_flags |= APK_FORCE; apk_flags |= APK_FORCE;
break; break;
case 'U':
apk_flags |= APK_UPDATE_CACHE;
break;
case 0x101: case 0x101:
apk_flags |= APK_PROGRESS; apk_flags |= APK_PROGRESS;
break; break;

View File

@ -46,6 +46,7 @@ extern unsigned int apk_flags;
#define APK_UPGRADE 0x0010 #define APK_UPGRADE 0x0010
#define APK_RECURSIVE 0x0020 #define APK_RECURSIVE 0x0020
#define APK_PREFER_AVAILABLE 0x0040 #define APK_PREFER_AVAILABLE 0x0040
#define APK_UPDATE_CACHE 0x0080
#define apk_error(args...) apk_log("ERROR: ", args); #define apk_error(args...) apk_log("ERROR: ", args);
#define apk_warning(args...) if (apk_verbosity > 0) { apk_log("WARNING: ", args); } #define apk_warning(args...) if (apk_verbosity > 0) { apk_log("WARNING: ", args); }

View File

@ -11,6 +11,7 @@
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h>
#include "apk_defines.h" #include "apk_defines.h"
#include "apk_applet.h" #include "apk_applet.h"

View File

@ -1026,7 +1026,7 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
struct apk_istream *is = NULL; struct apk_istream *is = NULL;
struct apk_bstream *bs = NULL; struct apk_bstream *bs = NULL;
struct apk_repository *repo; struct apk_repository *repo;
int r, n; int r, n = 1;
if (repository.ptr == NULL || *repository.ptr == '\0' if (repository.ptr == NULL || *repository.ptr == '\0'
|| *repository.ptr == '#') || *repository.ptr == '#')
@ -1045,9 +1045,13 @@ int apk_db_add_repository(apk_database_t _db, apk_blob_t repository)
if (apk_url_local_file(repo->url) == NULL) { if (apk_url_local_file(repo->url) == NULL) {
csum_blob(repository, repo->url_csum); csum_blob(repository, repo->url_csum);
if (apk_flags & APK_UPDATE_CACHE)
n = apk_repository_update(db, repo);
bs = apk_db_cache_open(db, repo->url_csum, apk_index_gz); bs = apk_db_cache_open(db, repo->url_csum, apk_index_gz);
if (bs == NULL) { if (bs == NULL) {
n = apk_repository_update(db, repo); if (n == 1)
n = apk_repository_update(db, repo);
if (n < 0) if (n < 0)
return n; return n;
bs = apk_db_cache_open(db, repo->url_csum, bs = apk_db_cache_open(db, repo->url_csum,