summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/db.c79
-rw-r--r--src/db.h1
-rw-r--r--src/package.c33
-rw-r--r--src/package.h3
-rw-r--r--src/pacman.c249
-rw-r--r--src/pacman.h6
-rw-r--r--src/pacsync.c35
7 files changed, 312 insertions, 94 deletions
diff --git a/src/db.c b/src/db.c
index 29135afd..3a208bea 100644
--- a/src/db.c
+++ b/src/db.c
@@ -71,7 +71,7 @@ PMList* db_loadpkgs(pacdb_t *db)
PMList *cache = NULL;
rewinddir(db->dir);
- while((info = db_scan(db, NULL, INFRQ_DESC)) != NULL) {
+ while((info = db_scan(db, NULL, INFRQ_DESC | INFRQ_DEPENDS)) != NULL) {
/* add to the collective */
/* we load all package names into a linear array first, so qsort can handle it */
if(arr == NULL) {
@@ -110,12 +110,12 @@ pkginfo_t* db_scan(pacdb_t *db, char *target, unsigned int inforeq)
if(target != NULL) {
/* search for a specific package (by name only) */
rewinddir(db->dir);
- /* read the . and .. first */
- ent = readdir(db->dir);
- ent = readdir(db->dir);
-
ent = readdir(db->dir);
while(!found && ent != NULL) {
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
+ ent = readdir(db->dir);
+ continue;
+ }
strncpy(name, ent->d_name, 255);
/* truncate the string at the second-to-last hyphen, */
/* which will give us the package name */
@@ -137,14 +137,14 @@ pkginfo_t* db_scan(pacdb_t *db, char *target, unsigned int inforeq)
} else {
/* normal iteration */
ent = readdir(db->dir);
- if(ent && !strcmp(ent->d_name, ".")) {
- ent = readdir(db->dir);
+ if(ent == NULL) {
+ return(NULL);
}
- if(ent && !strcmp(ent->d_name, "..")) {
+ if(!strcmp(ent->d_name, ".")) {
ent = readdir(db->dir);
}
- if(ent == NULL) {
- return(NULL);
+ if(!strcmp(ent->d_name, "..")) {
+ ent = readdir(db->dir);
}
}
return(db_read(db, ent, inforeq));
@@ -454,6 +454,65 @@ int db_write(pacdb_t *db, pkginfo_t *info)
return(0);
}
+void db_search(pacdb_t *db, PMList *cache, const char *treename, PMList *needles)
+{
+ PMList *i, *j;
+ if(needles == NULL || needles->data == NULL) {
+ return;
+ }
+
+ for(i = needles; i; i = i->next) {
+ char *targ = strdup(i->data);
+ strtoupper(targ);
+ for(j = cache; j; j = j->next) {
+ pkginfo_t *pkg = (pkginfo_t*)j->data;
+ char *haystack;
+ int match = 0;
+ /* check name */
+ haystack = strdup(pkg->name);
+ strtoupper(haystack);
+ if(strstr(haystack, targ)) {
+ match = 1;
+ }
+ FREE(haystack);
+
+ /* check description */
+ if(!match) {
+ haystack = strdup(pkg->desc);
+ strtoupper(haystack);
+ if(strstr(haystack, targ)) {
+ match = 1;
+ }
+ FREE(haystack);
+ }
+
+ /* check provides */
+ if(!match) {
+ PMList *m;
+ pkginfo_t *info = db_scan(db, pkg->name, INFRQ_DESC | INFRQ_DEPENDS);
+ if(info != NULL) {
+ for(m = info->provides; m; m = m->next) {
+ haystack = strdup(m->data);
+ strtoupper(haystack);
+ if(strstr(haystack, targ)) {
+ match = 1;
+ }
+ FREE(haystack);
+ }
+ FREEPKG(info);
+ }
+ }
+
+ if(match) {
+ printf("%s/%s %s\n ", treename, pkg->name, pkg->version);
+ indentprint(pkg->desc, 4);
+ printf("\n");
+ }
+ }
+ FREE(targ);
+ }
+}
+
PMList* db_find_conflicts(pacdb_t *db, PMList *targets, char *root)
{
diff --git a/src/db.h b/src/db.h
index 8d5282cf..6160a5f0 100644
--- a/src/db.h
+++ b/src/db.h
@@ -41,6 +41,7 @@ PMList* db_loadpkgs(pacdb_t *db);
pkginfo_t* db_scan(pacdb_t *db, char *target, unsigned int inforeq);
pkginfo_t* db_read(pacdb_t *db, struct dirent *ent, unsigned int inforeq);
int db_write(pacdb_t *db, pkginfo_t *info);
+void db_search(pacdb_t *db, PMList *cache, const char *treename, PMList *needles);
PMList* db_find_conflicts(pacdb_t *db, PMList* targets, char *root);
PMList *whatprovides(pacdb_t *db, char* package);
PMList *find_groups(pacdb_t *db);
diff --git a/src/package.c b/src/package.c
index 04153fb1..e7567d23 100644
--- a/src/package.c
+++ b/src/package.c
@@ -30,7 +30,7 @@
#include "util.h"
#include "package.h"
-pkginfo_t* load_pkg(char *pkgfile, unsigned short output)
+pkginfo_t* load_pkg(char *pkgfile)
{
char *expath;
int i;
@@ -66,7 +66,7 @@ pkginfo_t* load_pkg(char *pkgfile, unsigned short output)
mkstemp(descfile);
tar_extract_file(tar, descfile);
/* parse the info file */
- parse_descfile(descfile, info, &backup, output);
+ parse_descfile(descfile, info, &backup, 0);
if(!strlen(info->name)) {
fprintf(stderr, "load_pkg: missing package name in %s.\n", pkgfile);
FREEPKG(info);
@@ -379,4 +379,33 @@ void dump_pkg_sync(pkginfo_t *info)
printf("\nMD5 Sum : %s\n", info->md5sum);
}
+int split_pkgname(char *pkg, char **name, char **version)
+{
+ char tmp[256];
+ char *p, *q;
+
+ strncpy(tmp, pkg, 256);
+
+ p = strstr(tmp, ".pkg.tar.gz");
+ if(p == NULL) {
+ return(-1);
+ }
+ *p = 0;
+
+ for(q = --p; *q && *q != '-'; q--);
+ if(*q != '-' || q == tmp) {
+ return(-1);
+ }
+ for(p = --q; *p && *p != '-'; p--);
+ if(*p != '-' || p == tmp) {
+ return(-1);
+ }
+ *version = strdup(p+1);
+ *p = 0;
+
+ *name = strdup(tmp);
+
+ return(0);
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/package.h b/src/package.h
index 8d6f458c..6dcd8cf3 100644
--- a/src/package.h
+++ b/src/package.h
@@ -75,7 +75,7 @@ typedef struct __depmissing_t {
depend_t depend;
} depmissing_t;
-pkginfo_t* load_pkg(char *pkgfile, unsigned short output);
+pkginfo_t* load_pkg(char *pkgfile);
int parse_descfile(char *descfile, pkginfo_t *info, PMList **backup, int output);
pkginfo_t* newpkg();
void freepkg(pkginfo_t *pkg);
@@ -83,6 +83,7 @@ int pkgcmp(const void *p1, const void *p2);
int is_pkgin(pkginfo_t *needle, PMList *haystack);
void dump_pkg_full(pkginfo_t *info);
void dump_pkg_sync(pkginfo_t *info);
+int split_pkgname(char *pkg, char **name, char **version);
#endif
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman.c b/src/pacman.c
index e2db8721..3b5d3ddb 100644
--- a/src/pacman.c
+++ b/src/pacman.c
@@ -35,6 +35,7 @@
#include <zlib.h>
#include <syslog.h>
#include <libtar.h>
+#include <dirent.h>
/* pacman */
#include "rpmvercmp.h"
#include "md5.h"
@@ -68,6 +69,7 @@ unsigned short pmo_q_info = 0;
unsigned short pmo_q_list = 0;
unsigned short pmo_q_orphans = 0;
unsigned short pmo_q_owns = 0;
+unsigned short pmo_q_search = 0;
unsigned short pmo_r_cascade = 0;
unsigned short pmo_r_dbonly = 0;
unsigned short pmo_r_recurse = 0;
@@ -322,21 +324,96 @@ int pacman_sync(pacdb_t *db, PMList *targets)
}
if(pmo_s_clean) {
- mode_t oldmask;
+ if(pmo_s_clean == 1) {
+ /* incomplete cleanup: we keep latest packages and partial downloads */
+ DIR *dir;
+ struct dirent *ent;
+ PMList *cache = NULL;
+ PMList *clean = NULL;
+ PMList *i, *j;
+
+ printf("removing old packages from cache... ");
+ dir = opendir("/var/cache/pacman/pkg");
+ if(dir == NULL) {
+ fprintf(stderr, "error: could not access cache directory\n");
+ return(1);
+ }
+ rewinddir(dir);
+ while((ent = readdir(dir)) != NULL) {
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
+ continue;
+ }
+ cache = list_add(cache, strdup(ent->d_name));
+ }
+ closedir(dir);
- printf("removing packages from cache... ");
- if(rmrf("/var/cache/pacman/pkg")) {
- fprintf(stderr, "error: could not remove cache directory: %s\n", strerror(errno));
- return(1);
- }
+ for(i = cache; i; i = i->next) {
+ char *str = (char *)i->data;
+ char *name, *version;
- oldmask = umask(0000);
- if(makepath("/var/cache/pacman/pkg")) {
- fprintf(stderr, "error: could not create new cache directory: %s\n", strerror(errno));
- return(1);
- }
- umask(oldmask);
+ if(split_pkgname(str, &name, &version) != 0) {
+ clean = list_add(clean, strdup(str));
+ continue;
+ }
+ /* we keep partially downloaded files */
+ if(strstr(str, ".pkg.tar.gz.part")) {
+ FREE(name);
+ FREE(version);
+ continue;
+ }
+ for(j = i->next; j; j = j->next) {
+ char *s = (char *)j->data;
+ char *n, *v;
+ if(split_pkgname(s, &n, &v) != 0) {
+ continue;
+ }
+ if(!strcmp(name, n)) {
+ char *ptr;
+ if(rpmvercmp(version, v) < 0) {
+ ptr = str;
+ } else {
+ ptr = s;
+ }
+ if(!is_in(ptr, clean)) {
+ clean = list_add(clean, strdup(ptr));
+ }
+ }
+ FREE(n);
+ FREE(v);
+ }
+ FREE(name);
+ FREE(version);
+ }
+ FREELIST(cache);
+
+ for(i = clean; i; i = i->next) {
+ char path[PATH_MAX];
+
+ snprintf(path, PATH_MAX, "%s%s/%s", pmo_root, CACHEDIR, (char *)i->data);
+ unlink(path);
+ }
+ FREELIST(clean);
+ } else {
+ /* full cleanup */
+ mode_t oldmask;
+ char path[PATH_MAX];
+
+ snprintf(path, PATH_MAX, "%s%s", pmo_root, CACHEDIR);
+
+ printf("removing all packages from cache... ");
+ if(rmrf(path)) {
+ fprintf(stderr, "error: could not remove cache directory: %s\n", strerror(errno));
+ return(1);
+ }
+
+ oldmask = umask(0000);
+ if(makepath(path)) {
+ fprintf(stderr, "error: could not create new cache directory: %s\n", strerror(errno));
+ return(1);
+ }
+ umask(oldmask);
+ }
printf("done.\n");
return(0);
}
@@ -374,53 +451,9 @@ int pacman_sync(pacdb_t *db, PMList *targets)
if(pmo_s_search) {
/* search sync databases */
if(targets) {
- for(i = targets; i; i = i->next) {
- char *targ = strdup(i->data);
- strtoupper(targ);
- for(j = databases; j; j = j->next) {
- dbsync_t *dbs = (dbsync_t*)j->data;
- for(k = dbs->pkgcache; k; k = k->next) {
- pkginfo_t *pkg = (pkginfo_t*)k->data;
- char *haystack;
- PMList *m;
- int match = 0;
- /* check name */
- haystack = strdup(pkg->name);
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
- match = 1;
- }
- FREE(haystack);
-
- /* check description */
- haystack = strdup(pkg->desc);
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
- match = 1;
- }
- FREE(haystack);
-
- if(!match) {
- pkg = db_scan(dbs->db, pkg->name, INFRQ_DESC | INFRQ_DEPENDS);
- /* check provides */
- for(m = pkg->provides; m; m = m->next) {
- haystack = strdup(m->data);
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
- match = 1;
- }
- FREE(haystack);
- }
- }
-
- if(match) {
- printf("%s/%s %s\n ", dbs->sync->treename, pkg->name, pkg->version);
- indentprint(pkg->desc, 4);
- printf("\n");
- }
- }
- }
- FREE(targ);
+ for(j = databases; j; j = j->next) {
+ dbsync_t *dbs = (dbsync_t*)j->data;
+ db_search(dbs->db, dbs->pkgcache, dbs->sync->treename, targets);
}
} else {
for(j = databases; j; j = j->next) {
@@ -1381,7 +1414,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
for(targ = targets; targ; targ = targ->next) {
/* Populate the package struct */
vprint("reading %s... ", (char*)targ->data);
- info = load_pkg((char*)targ->data, 0);
+ info = load_pkg((char*)targ->data);
if(info == NULL) {
return(1);
}
@@ -1957,7 +1990,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
depmissing_t* miss = (depmissing_t*)j->data;
printf(" %s: is required by %s\n", miss->target, miss->depend.name);
}
- list_free(alltargs);
+ FREELISTPKGS(alltargs);
list_free(lp);
return(1);
}
@@ -1973,7 +2006,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
list_display("\nTargets:", alltargs);
/* get confirmation */
if(yesno("\nDo you want to remove these packages? [Y/n] ") == 0) {
- list_free(alltargs);
+ FREELISTPKGS(alltargs);
return(1);
}
}
@@ -2048,6 +2081,18 @@ int pacman_remove(pacdb_t *db, PMList *targets)
}
}
+ if(!pmo_upgrade) {
+ /* run the post-remove script if it exists */
+ snprintf(pm_install, PATH_MAX, "%s%s/%s/%s-%s/install", pmo_root, pmo_dbpath, db->treename, info->name, info->version);
+ if(!stat(pm_install, &buf)) {
+ vprint("Executing post-remove script...\n");
+ snprintf(pm_install, PATH_MAX, "%s/%s/%s-%s/install", pmo_dbpath, db->treename, info->name, info->version);
+ snprintf(line, PATH_MAX, "chroot %s /bin/sh %s post_remove %s", pmo_root, pm_install, info->version);
+
+ system(line);
+ }
+ }
+
/* remove the package from the database */
snprintf(line, PATH_MAX, "%s%s/%s/%s-%s", pmo_root, pmo_dbpath, db->treename,
info->name, info->version);
@@ -2118,7 +2163,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
}
}
- FREELIST(alltargs);
+ FREELISTPKGS(alltargs);
/* run ldconfig if it exists */
snprintf(line, PATH_MAX, "%setc/ld.so.conf", pmo_root);
@@ -2143,6 +2188,11 @@ int pacman_query(pacdb_t *db, PMList *targets)
PMList *targ, *lp, *q;
int done = 0;
+ if(pmo_q_search) {
+ db_search(db, pm_packages, "local", targets);
+ return(0);
+ }
+
for(targ = targets; !done; targ = (targ ? targ->next : NULL)) {
if(targets == NULL) {
done = 1;
@@ -2187,12 +2237,13 @@ int pacman_query(pacdb_t *db, PMList *targets)
fprintf(stderr, "error: no package file was specified for --file\n");
return(1);
}
- info = load_pkg(package, pmo_q_info);
+ info = load_pkg(package);
if(info == NULL) {
fprintf(stderr, "error: %s is not a package\n", package);
return(1);
}
if(pmo_q_info) {
+ dump_pkg_full(info);
printf("\n");
} else if(pmo_q_list) {
for(lp = info->files; lp; lp = lp->next) {
@@ -2670,8 +2721,26 @@ PMList* checkdeps(pacdb_t *db, unsigned short op, PMList *targets)
for(j = tp->conflicts; j; j = j->next) {
/* check targets against database */
for(k = pm_packages; k; k = k->next) {
+ int conflict = 0;
pkginfo_t *dp = (pkginfo_t*)k->data;
+ if(!strcmp(dp->name, tp->name)) {
+ /* a package cannot conflict with itself -- that's just not nice */
+ continue;
+ }
if(!strcmp(j->data, dp->name)) {
+ /* dp is listed in tp's conflict list */
+ conflict = 1;
+ } else {
+ /* see if dp provides something in tp's conflict list */
+ PMList *m;
+ for(m = dp->provides; m; m = m->next) {
+ if(!strcmp(m->data, j->data)) {
+ conflict = 1;
+ break;
+ }
+ }
+ }
+ if(conflict) {
MALLOC(miss, sizeof(depmissing_t));
miss->type = CONFLICT;
miss->depend.mod = DEP_ANY;
@@ -2685,14 +2754,32 @@ PMList* checkdeps(pacdb_t *db, unsigned short op, PMList *targets)
}
/* check targets against targets */
for(k = targets; k; k = k->next) {
- pkginfo_t *a = (pkginfo_t*)k->data;
- if(!strcmp(a->name, (char*)j->data)) {
+ int conflict = 0;
+ pkginfo_t *otp = (pkginfo_t*)k->data;
+ if(!strcmp(otp->name, tp->name)) {
+ /* a package cannot conflict with itself -- that's just not nice */
+ continue;
+ }
+ if(!strcmp(otp->name, (char*)j->data)) {
+ /* otp is listed in tp's conflict list */
+ conflict = 1;
+ } else {
+ /* see if otp provides something in tp's conflict list */
+ PMList *m;
+ for(m = otp->provides; m; m = m->next) {
+ if(!strcmp(m->data, j->data)) {
+ conflict = 1;
+ break;
+ }
+ }
+ }
+ if(conflict) {
MALLOC(miss, sizeof(depmissing_t));
miss->type = CONFLICT;
miss->depend.mod = DEP_ANY;
miss->depend.version[0] = '\0';
strncpy(miss->target, tp->name, 256);
- strncpy(miss->depend.name, a->name, 256);
+ strncpy(miss->depend.name, otp->name, 256);
if(!list_isin(baddeps, miss)) {
baddeps = list_add(baddeps, miss);
}
@@ -2703,7 +2790,24 @@ PMList* checkdeps(pacdb_t *db, unsigned short op, PMList *targets)
rewinddir(db->dir);
while((info = db_scan(db, NULL, INFRQ_DESC | INFRQ_DEPENDS)) != NULL) {
for(j = info->conflicts; j; j = j->next) {
+ int conflict = 0;
+ if(!strcmp(info->name, tp->name)) {
+ /* a package cannot conflict with itself -- that's just not nice */
+ continue;
+ }
if(!strcmp((char*)j->data, tp->name)) {
+ conflict = 1;
+ } else {
+ /* see if tp provides something in info's conflict list */
+ PMList *m;
+ for(m = tp->provides; m; m = m->next) {
+ if(!strcmp(m->data, j->data)) {
+ conflict = 1;
+ break;
+ }
+ }
+ }
+ if(conflict) {
MALLOC(miss, sizeof(depmissing_t));
miss->type = CONFLICT;
miss->depend.mod = DEP_ANY;
@@ -3015,7 +3119,7 @@ int parseargs(int op, int argc, char **argv)
case 'h': pmo_help = 1; break;
case 'V': pmo_version = 1; break;
case 'b': strcpy(pmo_dbpath, optarg); break;
- case 'c': pmo_s_clean = 1; pmo_r_cascade = 1; break;
+ case 'c': pmo_s_clean++; pmo_r_cascade = 1; break;
case 'd': pmo_nodeps = 1; break;
case 'e': pmo_q_orphans = 1; break;
case 'f': pmo_force = 1; break;
@@ -3030,7 +3134,7 @@ int parseargs(int op, int argc, char **argv)
perror("bad root path");
return(1);
} break;
- case 's': pmo_s_search = 1; pmo_r_recurse = 1; break;
+ case 's': pmo_s_search = 1; pmo_q_search = 1; pmo_r_recurse = 1; break;
case 'u': pmo_s_upgrade = 1; break;
case 'v': pmo_verbose = 1; break;
case 'w': pmo_s_downloadonly = 1; break;
@@ -3317,20 +3421,21 @@ void usage(int op, char *myname)
printf(" -o, --owns <file> query the package that owns <file>\n");
printf(" -p, --file pacman will query the package file [package] instead of\n");
printf(" looking in the database\n");
+ printf(" -s, --search search locally-installed packages for matching strings\n");
} else if(op == PM_SYNC) {
printf("usage: %s {-S --sync} [options] [package]\n", myname);
printf("options:\n");
- printf(" -c, --clean remove packages from cache directory to free up diskspace\n");
+ printf(" -c, --clean remove old packages from cache directory (use -cc for all)\n");
printf(" -d, --nodeps skip dependency checks\n");
printf(" -f, --force force install, overwrite conflicting files\n");
printf(" -g, --groups view all members of a package group\n");
printf(" -i, --info view package information\n");
printf(" -l, --list list all packages belonging to the specified repository\n");
printf(" -p, --print-uris print out download URIs for each package to be installed\n");
- printf(" -s, --search search sync database for matching strings\n");
+ printf(" -s, --search search remote repositories for matching strings\n");
printf(" -u, --sysupgrade upgrade all packages that are out of date\n");
printf(" -w, --downloadonly download packages, but do not install/upgrade anything\n");
- printf(" -y, --refresh download a fresh package sync database from the server\n");
+ printf(" -y, --refresh download fresh package databases from the server\n");
}
printf(" -v, --verbose be verbose\n");
printf(" -r, --root <path> set an alternate installation root\n");
diff --git a/src/pacman.h b/src/pacman.h
index 3bc7eb3b..bc8e530e 100644
--- a/src/pacman.h
+++ b/src/pacman.h
@@ -22,7 +22,7 @@
#define _PAC_PACMAN_H
#ifndef PACVER
-#define PACVER "2.7.7"
+#define PACVER "2.7.8"
#endif
#ifndef PKGDIR
@@ -33,6 +33,10 @@
#define PACCONF "etc/pacman.conf"
#endif
+#ifndef CACHEDIR
+#define CACHEDIR "var/cache/pacman/pkg"
+#endif
+
/* Operations */
#define PM_MAIN 1
#define PM_ADD 2
diff --git a/src/pacsync.c b/src/pacsync.c
index 0c41f543..d1045a63 100644
--- a/src/pacsync.c
+++ b/src/pacsync.c
@@ -182,6 +182,7 @@ int downloadfiles(PMList *servers, const char *localpath, PMList *files)
if(pmo_xfercommand) {
int ret;
+ int usepart = 0;
char *ptr1, *ptr2;
char origCmd[PATH_MAX];
char parsedCmd[PATH_MAX] = "";
@@ -190,9 +191,22 @@ int downloadfiles(PMList *servers, const char *localpath, PMList *files)
/* build the full download url */
snprintf(url, PATH_MAX, "%s://%s%s%s", server->protocol, server->server,
server->path, fn);
- /* replace all occurrences of %u with the download URL */
+ /* replace all occurrences of %o with fn.part */
strncpy(origCmd, pmo_xfercommand, sizeof(origCmd));
ptr1 = origCmd;
+ while((ptr2 = strstr(ptr1, "%o"))) {
+ usepart = 1;
+ ptr2[0] = '\0';
+ strcat(parsedCmd, ptr1);
+ strcat(parsedCmd, fn);
+ strcat(parsedCmd, ".part");
+ ptr1 = ptr2 + 2;
+ }
+ strcat(parsedCmd, ptr1);
+ /* replace all occurrences of %u with the download URL */
+ strncpy(origCmd, parsedCmd, sizeof(origCmd));
+ parsedCmd[0] = '\0';
+ ptr1 = origCmd;
while((ptr2 = strstr(ptr1, "%u"))) {
ptr2[0] = '\0';
strcat(parsedCmd, ptr1);
@@ -214,11 +228,16 @@ int downloadfiles(PMList *servers, const char *localpath, PMList *files)
return(1);
} else if(ret != 0) {
/* download failed */
- vprint("XferCommand command returned non-zero status code (%d)\n",
- WEXITSTATUS(ret));
+ vprint("XferCommand command returned non-zero status code (%d)\n", ret);
} else {
/* download was successful */
complete = list_add(complete, fn);
+ if(usepart) {
+ char fnpart[PATH_MAX];
+ /* rename "output.part" file to "output" file */
+ snprintf(fnpart, PATH_MAX, "%s.part", fn);
+ rename(fnpart, fn);
+ }
}
chdir(cwd);
} else {
@@ -337,7 +356,7 @@ int downloadfiles(PMList *servers, const char *localpath, PMList *files)
for(j = strlen(out); j < maxcols-64; j++) {
printf(" ");
}
- fputs("] 100% | LOCAL |", stdout);
+ fputs("] 100% LOCAL ", stdout);
} else {
log_progress(control, fsz-offset, &fsz);
}
@@ -351,9 +370,9 @@ int downloadfiles(PMList *servers, const char *localpath, PMList *files)
}
}
if(!pmo_xfercommand) {
- if(!strcmp(server->protocol, "ftp")) {
+ if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
FtpQuit(control);
- } else if(!strcmp(server->protocol, "http")) {
+ } else if(!strcmp(server->protocol, "http") || pmo_proxyhost) {
HttpQuit(control);
}
}
@@ -408,9 +427,9 @@ static int log_progress(netbuf *ctl, int xfered, void *arg)
(i < cur) ? printf("#") : printf(" ");
}
if(rate > 1000) {
- printf("] %3d%%| %6dK| %6.0fK/s| %02d:%02d:%02d\r", pct, ((xfered+offset) / 1024), rate, eta_h, eta_m, eta_s);
+ printf("] %3d%% %6dK %6.0fK/s %02d:%02d:%02d\r", pct, ((xfered+offset) / 1024), rate, eta_h, eta_m, eta_s);
} else {
- printf("] %3d%%| %6dK| %6.1fK/s| %02d:%02d:%02d\r", pct, ((xfered+offset) / 1024), rate, eta_h, eta_m, eta_s);
+ printf("] %3d%% %6dK %6.1fK/s %02d:%02d:%02d\r", pct, ((xfered+offset) / 1024), rate, eta_h, eta_m, eta_s);
}
fflush(stdout);
return(1);