summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-03-16 21:21:06 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-03-16 21:21:06 +0000
commitab7ca5dc72d4bd1eb08d210ff911352d23bd1072 (patch)
tree035c22bcfebbf3e00f88368ae02ac0263b058f91
parent2ce1105900fcbb1fa2ad176dae74e5f5290af4a4 (diff)
downloadpacman-ab7ca5dc72d4bd1eb08d210ff911352d23bd1072.tar.xz
- reworked sync_synctree() to make use of alpm_db_update()
- dropped unpack()
-rw-r--r--src/pacman/sync.c46
-rw-r--r--src/pacman/util.c75
-rw-r--r--src/pacman/util.h4
3 files changed, 21 insertions, 104 deletions
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index e4fe867c..e581579e 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -156,52 +156,44 @@ static int sync_cleancache(int level)
static int sync_synctree(list_t *syncs)
{
- char path[PATH_MAX];
- mode_t oldmask;
- list_t *files = NULL;
+ char *root, *dbpath;
list_t *i;
- int success = 0;
+ int ret = 0;
+
+ alpm_get_option(PM_OPT_ROOT, (long *)&root);
+ alpm_get_option(PM_OPT_DBPATH, (long *)&dbpath);
for(i = syncs; i; i = i->next) {
+ char path[PATH_MAX];
+ list_t *files = NULL;
sync_t *sync = (sync_t *)i->data;
/* build a one-element list */
snprintf(path, PATH_MAX, "%s"PM_EXT_DB, sync->treename);
files = list_add(files, strdup(path));
- success = 1;
- if(downloadfiles(sync->servers, pmo_dbpath, files)) {
+ snprintf(path, PATH_MAX, "%s%s", root, dbpath);
+
+ if(downloadfiles(sync->servers, path, files)) {
fprintf(stderr, "failed to synchronize %s\n", sync->treename);
- success = 0;
+ FREELIST(files);
+ ret--;
+ continue;
}
FREELIST(files);
- snprintf(path, PATH_MAX, "%s/%s"PM_EXT_DB, pmo_dbpath, sync->treename);
-
- if(success) {
- char ldir[PATH_MAX];
-
- snprintf(ldir, PATH_MAX, "%s/%s", pmo_dbpath, sync->treename);
- /* remove the old dir */
- vprint("removing %s (if it exists)\n", ldir);
- rmrf(ldir);
- /* make the new dir */
- oldmask = umask(0000);
- mkdir(ldir, 0755);
- umask(oldmask);
-
- /* uncompress the sync database */
- vprint("Unpacking %s...\n", path);
- if(unpack(path, ldir, NULL)) {
- return(1);
- }
+ snprintf(path, PATH_MAX, "%s%s/%s"PM_EXT_DB, root, dbpath, sync->treename);
+ if(alpm_db_update(sync->treename, path) == -1) {
+ fprintf(stderr, "error: %s\n", alpm_strerror(pm_errno));
+ ret--;
}
+
/* remove the .tar.gz */
unlink(path);
}
- return(!success);
+ return(ret);
}
static int sync_search(list_t *syncs, list_t *targets)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 56c3349b..5ae26149 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -28,84 +28,11 @@
#include <fcntl.h>
#include <ctype.h>
#include <dirent.h>
-#include <zlib.h>
-#include <libtar.h>
+#include <unistd.h>
/* pacman */
#include "util.h"
-/* borrowed and modified from Per Liden's pkgutils (http://crux.nu) */
-long gzopen_frontend(char *pathname, int oflags, int mode)
-{
- char *gzoflags;
- int fd;
- gzFile gzf;
-
- switch (oflags & O_ACCMODE) {
- case O_WRONLY:
- gzoflags = "w";
- break;
- case O_RDONLY:
- gzoflags = "r";
- break;
- case O_RDWR:
- default:
- errno = EINVAL;
- return -1;
- }
-
- if((fd = open(pathname, oflags, mode)) == -1) {
- return -1;
- }
- if((oflags & O_CREAT) && fchmod(fd, mode)) {
- return -1;
- }
- if(!(gzf = gzdopen(fd, gzoflags))) {
- errno = ENOMEM;
- return -1;
- }
-
- return (long)gzf;
-}
-
-int unpack(char *archive, const char *prefix, const char *fn)
-{
- TAR *tar = NULL;
- char expath[PATH_MAX];
- tartype_t gztype = {
- (openfunc_t) gzopen_frontend,
- (closefunc_t)gzclose,
- (readfunc_t) gzread,
- (writefunc_t)gzwrite
- };
-
- /* open the .tar.gz package */
- if(tar_open(&tar, archive, &gztype, O_RDONLY, 0, TAR_GNU) == -1) {
- perror(archive);
- return(1);
- }
- while(!th_read(tar)) {
- if(fn && strcmp(fn, th_get_pathname(tar))) {
- if(TH_ISREG(tar) && tar_skip_regfile(tar)) {
- char errorstr[255];
- snprintf(errorstr, 255, "bad tar archive: %s", archive);
- perror(errorstr);
- tar_close(tar);
- return(1);
- }
- continue;
- }
- snprintf(expath, PATH_MAX, "%s/%s", prefix, th_get_pathname(tar));
- if(tar_extract_file(tar, expath)) {
- fprintf(stderr, "could not extract %s: %s\n", th_get_pathname(tar), strerror(errno));
- }
- if(fn) break;
- }
- tar_close(tar);
-
- return(0);
-}
-
/* does the same thing as 'mkdir -p' */
int makepath(char *path)
{
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 15ce8043..b181dbd1 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -26,10 +26,8 @@
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", b); \
exit(1); }} else p = NULL; } while(0)
-#define FREE(p) do { if (p) { free(p); (p)= NULL; }} while(0)
+#define FREE(p) do { if (p) { free(p); (p) = NULL; }} while(0)
-long gzopen_frontend(char *pathname, int oflags, int mode);
-int unpack(char *archive, const char *prefix, const char *fn);
int makepath(char *path);
int rmrf(char *path);
void indentprint(char *str, int indent);