mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 07:48:50 -05:00
- reworked sync_synctree() to make use of alpm_db_update()
- dropped unpack()
This commit is contained in:
parent
2ce1105900
commit
ab7ca5dc72
@ -156,52 +156,44 @@ static int sync_cleancache(int level)
|
|||||||
|
|
||||||
static int sync_synctree(list_t *syncs)
|
static int sync_synctree(list_t *syncs)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char *root, *dbpath;
|
||||||
mode_t oldmask;
|
|
||||||
list_t *files = NULL;
|
|
||||||
list_t *i;
|
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) {
|
for(i = syncs; i; i = i->next) {
|
||||||
|
char path[PATH_MAX];
|
||||||
|
list_t *files = NULL;
|
||||||
sync_t *sync = (sync_t *)i->data;
|
sync_t *sync = (sync_t *)i->data;
|
||||||
|
|
||||||
/* build a one-element list */
|
/* build a one-element list */
|
||||||
snprintf(path, PATH_MAX, "%s"PM_EXT_DB, sync->treename);
|
snprintf(path, PATH_MAX, "%s"PM_EXT_DB, sync->treename);
|
||||||
files = list_add(files, strdup(path));
|
files = list_add(files, strdup(path));
|
||||||
|
|
||||||
success = 1;
|
snprintf(path, PATH_MAX, "%s%s", root, dbpath);
|
||||||
if(downloadfiles(sync->servers, pmo_dbpath, files)) {
|
|
||||||
|
if(downloadfiles(sync->servers, path, files)) {
|
||||||
fprintf(stderr, "failed to synchronize %s\n", sync->treename);
|
fprintf(stderr, "failed to synchronize %s\n", sync->treename);
|
||||||
success = 0;
|
FREELIST(files);
|
||||||
|
ret--;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
FREELIST(files);
|
FREELIST(files);
|
||||||
snprintf(path, PATH_MAX, "%s/%s"PM_EXT_DB, pmo_dbpath, sync->treename);
|
|
||||||
|
|
||||||
if(success) {
|
snprintf(path, PATH_MAX, "%s%s/%s"PM_EXT_DB, root, dbpath, sync->treename);
|
||||||
char ldir[PATH_MAX];
|
if(alpm_db_update(sync->treename, path) == -1) {
|
||||||
|
fprintf(stderr, "error: %s\n", alpm_strerror(pm_errno));
|
||||||
snprintf(ldir, PATH_MAX, "%s/%s", pmo_dbpath, sync->treename);
|
ret--;
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove the .tar.gz */
|
/* remove the .tar.gz */
|
||||||
unlink(path);
|
unlink(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(!success);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sync_search(list_t *syncs, list_t *targets)
|
static int sync_search(list_t *syncs, list_t *targets)
|
||||||
|
@ -28,84 +28,11 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <zlib.h>
|
#include <unistd.h>
|
||||||
#include <libtar.h>
|
|
||||||
|
|
||||||
/* pacman */
|
/* pacman */
|
||||||
#include "util.h"
|
#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' */
|
/* does the same thing as 'mkdir -p' */
|
||||||
int makepath(char *path)
|
int makepath(char *path)
|
||||||
{
|
{
|
||||||
|
@ -26,10 +26,8 @@
|
|||||||
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", b); \
|
fprintf(stderr, "malloc failure: could not allocate %d bytes\n", b); \
|
||||||
exit(1); }} else p = NULL; } while(0)
|
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 makepath(char *path);
|
||||||
int rmrf(char *path);
|
int rmrf(char *path);
|
||||||
void indentprint(char *str, int indent);
|
void indentprint(char *str, int indent);
|
||||||
|
Loading…
Reference in New Issue
Block a user