mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 08:18:51 -05:00
Style cleanups in clean cache code
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
d6a9436143
commit
986edb8bd4
@ -42,6 +42,7 @@
|
|||||||
static int sync_cleandb(const char *dbpath, int keep_used) {
|
static int sync_cleandb(const char *dbpath, int keep_used) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
|
alpm_list_t *syncdbs;
|
||||||
|
|
||||||
dir = opendir(dbpath);
|
dir = opendir(dbpath);
|
||||||
if(dir == NULL) {
|
if(dir == NULL) {
|
||||||
@ -49,12 +50,13 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
|
|||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
syncdbs = alpm_option_get_syncdbs();
|
||||||
|
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
/* step through the directory one file at a time */
|
/* step through the directory one file at a time */
|
||||||
while((ent = readdir(dir)) != NULL) {
|
while((ent = readdir(dir)) != NULL) {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
alpm_list_t *syncdbs = NULL, *i;
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
const char *dname = ent->d_name;
|
const char *dname = ent->d_name;
|
||||||
size_t len;
|
size_t len;
|
||||||
@ -77,7 +79,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
|
|||||||
/* remove all non-skipped directories and non-database files */
|
/* remove all non-skipped directories and non-database files */
|
||||||
stat(path, &buf);
|
stat(path, &buf);
|
||||||
len = strlen(path);
|
len = strlen(path);
|
||||||
if(S_ISDIR(buf.st_mode) || strcmp(path+(len-3),".db") != 0) {
|
if(S_ISDIR(buf.st_mode) || strcmp(path + len - 3, ".db") != 0) {
|
||||||
if(rmrf(path)) {
|
if(rmrf(path)) {
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR,
|
pm_fprintf(stderr, PM_LOG_ERROR,
|
||||||
_("could not remove %s\n"), path);
|
_("could not remove %s\n"), path);
|
||||||
@ -88,9 +90,9 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(keep_used) {
|
if(keep_used) {
|
||||||
|
alpm_list_t *i;
|
||||||
len = strlen(dname);
|
len = strlen(dname);
|
||||||
char *dbname = strndup(dname, len-3);
|
char *dbname = strndup(dname, len - 3);
|
||||||
syncdbs = alpm_option_get_syncdbs();
|
|
||||||
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
|
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
|
||||||
pmdb_t *db = alpm_list_getdata(i);
|
pmdb_t *db = alpm_list_getdata(i);
|
||||||
found = !strcmp(dbname, alpm_db_get_name(db));
|
found = !strcmp(dbname, alpm_db_get_name(db));
|
||||||
@ -126,9 +128,9 @@ static int sync_cleandb_all(void) {
|
|||||||
if(!yesno(_("Do you want to remove unused repositories?"))) {
|
if(!yesno(_("Do you want to remove unused repositories?"))) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
/* The sync dbs were previously put in dbpath/, but are now in dbpath/sync/,
|
/* 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/
|
* We will clean everything in dbpath/ except local/, sync/ and db.lck, and
|
||||||
* and db.lck) and only the unused sync dbs in dbpath/sync/ */
|
* only the unused sync dbs in dbpath/sync/ */
|
||||||
ret += sync_cleandb(dbpath, 0);
|
ret += sync_cleandb(dbpath, 0);
|
||||||
|
|
||||||
sprintf(newdbpath, "%s%s", dbpath, "sync/");
|
sprintf(newdbpath, "%s%s", dbpath, "sync/");
|
||||||
|
Loading…
Reference in New Issue
Block a user