reworked sync_cleanup

This commit is contained in:
Aurelien Foret 2005-04-02 20:25:24 +00:00
parent ffb54aba32
commit 82de25badf

View file

@ -35,6 +35,7 @@
#include "list.h" #include "list.h"
#include "package.h" #include "package.h"
#include "db.h" #include "db.h"
#include "trans.h"
#include "sync.h" #include "sync.h"
#include "pacman.h" #include "pacman.h"
@ -73,10 +74,10 @@ static int sync_cleancache(int level)
snprintf(dirpath, PATH_MAX, "%s"CACHEDIR, root); snprintf(dirpath, PATH_MAX, "%s"CACHEDIR, root);
printf("removing old packages from cache... "); MSG(NL, "removing old packages from cache... ");
dir = opendir(dirpath); dir = opendir(dirpath);
if(dir == NULL) { if(dir == NULL) {
fprintf(stderr, "error: could not access cache directory\n"); ERR(NL, "could not access cache directory\n");
return(1); return(1);
} }
rewinddir(dir); rewinddir(dir);
@ -135,27 +136,23 @@ static int sync_cleancache(int level)
} }
FREELIST(clean); FREELIST(clean);
} else { } else {
/* ORE /* full cleanup */
// full cleanup
mode_t oldmask;
char path[PATH_MAX]; char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s"CACHEDIR, root); snprintf(path, PATH_MAX, "%s"CACHEDIR, root);
printf("removing all packages from cache... "); MSG(NL, "removing all packages from cache... ");
if(rmrf(path)) { if(rmrf(path)) {
fprintf(stderr, "error: could not remove cache directory\n"); ERR(NL, "could not remove cache directory\n");
return(1); return(1);
} }
oldmask = umask(0000);
if(makepath(path)) { if(makepath(path)) {
fprintf(stderr, "error: could not create new cache directory\n"); ERR(NL, "could not create new cache directory\n");
return(1); return(1);
} }
umask(oldmask);*/
} }
printf("done.\n"); MSG(CL, "done.\n");
return(0); return(0);
} }
@ -422,7 +419,7 @@ int pacman_sync(list_t *targets)
/* Step 1: create a new transaction... /* Step 1: create a new transaction...
*/ */
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, pmo_flags, NULL) == -1) { if(alpm_trans_init(PM_TRANS_TYPE_SYNC, pmo_flags, cb_trans) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno)); ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
retval = 1; retval = 1;
goto cleanup; goto cleanup;
@ -488,6 +485,7 @@ int pacman_sync(list_t *targets)
} }
} }
alpm_list_free(data); alpm_list_free(data);
data = NULL;
} }
/* and add targets to it /* and add targets to it
@ -495,6 +493,8 @@ int pacman_sync(list_t *targets)
for(i = targets; i; i = i->next) { for(i = targets; i; i = i->next) {
char *targ = i->data; char *targ = i->data;
printf("TARGET=%s\n", targ);
if(alpm_trans_addtarget(targ) == -1) { if(alpm_trans_addtarget(targ) == -1) {
if(pm_errno == PM_ERR_PKG_NOT_FOUND) { if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
PM_GRP *grp; PM_GRP *grp;
@ -536,8 +536,6 @@ int pacman_sync(list_t *targets)
} }
} }
PM_LIST_display("target :", alpm_trans_getinfo(PM_TRANS_TARGETS));
/* Step 2: "compute" the transaction based on targets and flags */ /* Step 2: "compute" the transaction based on targets and flags */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
ERR(NL, "failed to prepare transaction (%s)\n", alpm_strerror(pm_errno)); ERR(NL, "failed to prepare transaction (%s)\n", alpm_strerror(pm_errno));
@ -545,7 +543,7 @@ int pacman_sync(list_t *targets)
} }
/* list targets */ /* list targets */
if(final && !pmo_s_printuris) { if(!pmo_s_printuris) {
list_t *list = NULL; list_t *list = NULL;
char *str; char *str;
unsigned long totalsize = 0; unsigned long totalsize = 0;
@ -652,12 +650,9 @@ int pacman_sync(list_t *targets)
MSG(NL, "\n:: Retrieving packages from %s...\n", current->treename); MSG(NL, "\n:: Retrieving packages from %s...\n", current->treename);
fflush(stdout); fflush(stdout);
if(stat(ldir, &buf)) { if(stat(ldir, &buf)) {
mode_t oldmask;
/* no cache directory.... try creating it */ /* no cache directory.... try creating it */
MSG(NL, "warning: no %s cache exists. creating...", ldir); MSG(NL, "warning: no %s cache exists. creating...", ldir);
alpm_logaction("warning: no %s cache exists. creating...", ldir); alpm_logaction("warning: no %s cache exists. creating...", ldir);
oldmask = umask(0000);
if(makepath(ldir)) { if(makepath(ldir)) {
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink /* couldn't mkdir the cache directory, so fall back to /tmp and unlink
* the package afterwards. * the package afterwards.
@ -667,7 +662,6 @@ int pacman_sync(list_t *targets)
snprintf(ldir, PATH_MAX, "/tmp"); snprintf(ldir, PATH_MAX, "/tmp");
varcache = 0; varcache = 0;
} }
umask(oldmask);
} }
if(downloadfiles(current->servers, ldir, files)) { if(downloadfiles(current->servers, ldir, files)) {
ERR(NL, "failed to retrieve some files from %s\n", current->treename); ERR(NL, "failed to retrieve some files from %s\n", current->treename);