summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-02-19 15:47:05 +0100
committerDan McGee <dan@archlinux.org>2008-02-19 15:47:05 +0100
commitfc9d12bef039f558d9731c7dcb2f441ad5832def (patch)
tree8716a012b22ea6f7c26fd9246a37c2f744b6ba78
parent5676dbae4de0504a62758046c4974c2522789202 (diff)
downloadpacman-fc9d12bef039f558d9731c7dcb2f441ad5832def.tar.gz
pacman-fc9d12bef039f558d9731c7dcb2f441ad5832def.tar.xz
When cleaning DBs, only look at directories
FS#9609 brought up an interesting issue where a user was prompted to remove db.lck when running a -Sc operation concurrently with an -Syu operation during a long download. Although there are other problems here, this fixes the issue where files other than directories could be considered to be databases. Fix this. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/sync.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 27218d61..244fedce 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -25,6 +25,7 @@
#include <limits.h>
#include <unistd.h>
#include <dirent.h>
+#include <sys/stat.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -57,6 +58,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
/* step through the directory one file at a time */
while((ent = readdir(dir)) != NULL) {
char path[PATH_MAX];
+ struct stat buf;
alpm_list_t *syncdbs = NULL, *i;
int found = 0;
char *dname = ent->d_name;
@@ -68,6 +70,15 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
if(!strcmp(dname, "sync") || !strcmp(dname, "local")) {
continue;
}
+
+ /* build the full path */
+ snprintf(path, PATH_MAX, "%s%s", dbpath, ent->d_name);
+ /* skip entries that are not dirs (lock file, etc.) */
+ stat(path, &buf);
+ if(!S_ISDIR(buf.st_mode)) {
+ continue;
+ }
+
if(keep_used) {
syncdbs = alpm_option_get_syncdbs();
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
@@ -78,9 +89,6 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
/* 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;
}