diff options
Diffstat (limited to 'src/pacman/sync.c')
-rw-r--r-- | src/pacman/sync.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c index b2994389..7353f7ee 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -1,7 +1,7 @@ /* * sync.c * - * Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org> + * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> * * This program is free software; you can redistribute it and/or modify @@ -37,9 +37,7 @@ #include "package.h" #include "conf.h" -extern pmdb_t *db_local; - -/* if keep_used != 0, then the dirnames which match an used syncdb +/* if keep_used != 0, then the db files which match an used syncdb * will be kept */ static int sync_cleandb(const char *dbpath, int keep_used) { DIR *dir; @@ -59,31 +57,47 @@ static int sync_cleandb(const char *dbpath, int keep_used) { alpm_list_t *syncdbs = NULL, *i; int found = 0; const char *dname = ent->d_name; + size_t len; - if(!strcmp(dname, ".") || !strcmp(dname, "..")) { + if(strcmp(dname, ".") == 0 || strcmp(dname, "..") == 0) { continue; } /* skip the local and sync directories */ - if(!strcmp(dname, "sync") || !strcmp(dname, "local")) { + if(strcmp(dname, "sync") == 0 || strcmp(dname, "local") == 0) { + continue; + } + /* skip the db.lck file */ + if(strcmp(dname, "db.lck") == 0) { continue; } /* build the full path */ snprintf(path, PATH_MAX, "%s%s", dbpath, dname); - /* skip entries that are not dirs (lock file, etc.) */ + + /* remove all non-skipped directories and non-database files */ stat(path, &buf); - if(!S_ISDIR(buf.st_mode)) { + len = strlen(path); + if(S_ISDIR(buf.st_mode) || strcmp(path+(len-3),".db") != 0) { + if(rmrf(path)) { + pm_fprintf(stderr, PM_LOG_ERROR, + _("could not remove %s\n"), path); + closedir(dir); + return(1); + } continue; } if(keep_used) { + len = strlen(dname); + char *dbname = strndup(dname, len-3); syncdbs = alpm_option_get_syncdbs(); for(i = syncdbs; i && !found; i = alpm_list_next(i)) { pmdb_t *db = alpm_list_getdata(i); - found = !strcmp(dname, alpm_db_get_name(db)); + found = !strcmp(dbname, alpm_db_get_name(db)); } + free(dbname); } - /* We have a directory that doesn't match any syncdb. + /* We have a database that doesn't match any syncdb. * Ask the user if he wants to remove it. */ if(!found) { if(!yesno(_("Do you want to remove %s?"), path)) { @@ -92,7 +106,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) { if(rmrf(path)) { pm_fprintf(stderr, PM_LOG_ERROR, - _("could not remove repository directory\n")); + _("could not remove %s\n"), path); closedir(dir); return(1); } @@ -113,8 +127,8 @@ static int sync_cleandb_all(void) { return(0); } /* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/, - * so we will clean everything in dbpath/ (except dbpath/local/ and dbpath/sync/, - * and only the unused sync dbs in dbpath/sync/ */ + * so we will clean everything in dbpath/ (except dbpath/local/ and dbpath/sync/ + * and db.lck) and only the unused sync dbs in dbpath/sync/ */ ret += sync_cleandb(dbpath, 0); sprintf(newdbpath, "%s%s", dbpath, "sync/"); @@ -128,6 +142,7 @@ static int sync_cleancache(int level) { alpm_list_t *i; alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + pmdb_t *db_local = alpm_option_get_localdb(); int ret = 0; for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) { @@ -178,7 +193,7 @@ static int sync_cleancache(int level) pmpkg_t *localpkg = NULL, *pkg = NULL; alpm_list_t *j; - if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) { + if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { continue; } /* build the full filepath */ @@ -279,7 +294,7 @@ static int sync_synctree(int level, alpm_list_t *syncs) return(success > 0); } -static void print_installed(pmpkg_t *pkg) +static void print_installed(pmdb_t *db_local, pmpkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); const char *pkgver = alpm_pkg_get_version(pkg); @@ -300,6 +315,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) alpm_list_t *i, *j, *ret; int freelist; int found = 0; + pmdb_t *db_local = alpm_option_get_localdb(); for(i = syncs; i; i = alpm_list_next(i)) { pmdb_t *db = alpm_list_getdata(i); @@ -330,7 +346,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) /* print the package size with the output if ShowSize option set */ if(!config->quiet && config->showsize) { /* Convert byte size to MB */ - double mbsize = alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); + double mbsize = (double)alpm_pkg_get_size(pkg) / (1024.0 * 1024.0); printf(" [%.2f MB]", mbsize); } @@ -350,7 +366,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets) printf(")"); } - print_installed(pkg); + print_installed(db_local, pkg); /* we need a newline and initial indent first */ printf("\n "); @@ -503,6 +519,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets) static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) { alpm_list_t *i, *j, *ls = NULL; + pmdb_t *db_local = alpm_option_get_localdb(); if(targets) { for(i = targets; i; i = alpm_list_next(i)) { @@ -540,7 +557,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) if (!config->quiet) { printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); - print_installed(pkg); + print_installed(db_local, pkg); printf("\n"); } else { printf("%s\n", alpm_pkg_get_name(pkg)); @@ -555,7 +572,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets) return(0); } -static alpm_list_t *syncfirst() { +static alpm_list_t *syncfirst(void) { alpm_list_t *i, *res = NULL; for(i = config->syncfirst; i; i = alpm_list_next(i)) { @@ -666,7 +683,7 @@ static int sync_trans(alpm_list_t *targets) const char *package2 = alpm_conflict_get_package2(conflict); const char *reason = alpm_conflict_get_reason(conflict); /* only print reason if it contains new information */ - if(!strcmp(package1, reason) || !strcmp(package2, reason)) { + if(strcmp(package1, reason) == 0 || strcmp(package2, reason) == 0) { printf(_(":: %s and %s are in conflict\n"), package1, package2); } else { printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason); |