summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2007-11-17 22:52:03 +0100
committerDan McGee <dan@archlinux.org>2007-11-18 12:37:16 -0600
commitb118ce55bd01c7ebd42b5b6d4a0f34aa925701d8 (patch)
tree5817b2a2cf450d21597635f3861f59f4735a42c4 /src
parent55a7455135e2d8f2e118928f634dc7976ab6c8b4 (diff)
downloadpacman-b118ce55bd01c7ebd42b5b6d4a0f34aa925701d8.tar.xz
Extend the -Sc operation to also clean up unused sync databases.
We discussed this with stonecrest on IRC : 20:46 stonecrest >> someone brings up a good point.. why aren't repos that aren't in the pacman.conf removed from /var/lib/pacman? 20:46 stonecrest >> i have 118mb and 24 dirs in there, but only 5 repos at present 21:26 stonecrest >> shining: i guess you could prompt the user on deleting every dir in /var/lib/pacman.. since it shouldn't happen that often except for the first time 21:30 stonecrest >> could be part of pacman -Sc.. what else were you thinking? I already heard about this before, but it sounded dangerous to me. I didn't even think about a simple prompt. I also didn't know where this code would fit. And it fits well with -Sc, I borrowed most of the code from sync_cleancache. Example session : Cache directory: /var/cache/pacman/pkg/ Do you want to remove non-installed packages from cache? [Y/n] n Database directory: /var/lib/pacman/ Do you want to remove unused repositories? [Y/n] Do you want to remove /var/lib/pacman/sync/pacman-git? [Y/n] Do you want to remove /var/lib/pacman/sync/deltatest? [Y/n] Database directory cleaned up Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/sync.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index bb48cf98..bd29fc9c 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -43,6 +43,76 @@
extern pmdb_t *db_local;
+static int sync_cleandb(const char *dbpath) {
+ DIR *dir;
+ struct dirent *ent;
+
+ dir = opendir(dbpath);
+ if(dir == NULL) {
+ fprintf(stderr, _("error: could not access database directory\n"));
+ return(1);
+ }
+
+ rewinddir(dir);
+ /* step through the directory one file at a time */
+ while((ent = readdir(dir)) != NULL) {
+ char path[PATH_MAX];
+ alpm_list_t *syncdbs = NULL, *i;
+ int found = 0;
+ char *dname = ent->d_name;
+
+ if(!strcmp(dname, ".") || !strcmp(dname, "..")) {
+ continue;
+ }
+ /* skip the local and sync directories */
+ if(!strcmp(dname, "sync") || !strcmp(dname, "local")) {
+ continue;
+ }
+ 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));
+ }
+
+ /* We have a directory that doesn't match any syncdb.
+ * Ask the user if he wants to remove it. */
+ if(!found) {
+ /* build the full path */
+ snprintf(path, PATH_MAX, "%s%s", dbpath, ent->d_name);
+
+ if(!yesno(_("Do you want to remove %s? [Y/n] "), path)) {
+ continue;
+ }
+
+ if(rmrf(path)) {
+ fprintf(stderr, _("error: could not remove repository directory\n"));
+ return(1);
+ }
+ }
+
+ }
+ return(0);
+}
+
+static int sync_cleandb_all(void) {
+ const char *dbpath = alpm_option_get_dbpath();
+ char newdbpath[PATH_MAX];
+
+ printf(_("Database directory: %s\n"), dbpath);
+ if(!yesno(_("Do you want to remove unused repositories? [Y/n] "))) {
+ return(0);
+ }
+ /* The sync dbs were previously put in dbpath, but are now in dbpath/sync,
+ * so we will clean both directories */
+ sync_cleandb(dbpath);
+
+ sprintf(newdbpath, "%s%s", dbpath, "sync/");
+ sync_cleandb(newdbpath);
+
+ printf(_("Database directory cleaned up\n"));
+ return(0);
+}
+
static int sync_cleancache(int level)
{
/* TODO for now, just mess with the first cache directory */
@@ -655,7 +725,9 @@ int pacman_sync(alpm_list_t *targets)
/* clean the cache */
if(config->op_s_clean) {
- return(sync_cleancache(config->op_s_clean));
+ int ret = sync_cleancache(config->op_s_clean);
+ ret += sync_cleandb_all();
+ return(ret);
}
/* ensure we have at least one valid sync db set up */