Imported from pacman-2.7.3.tar.gz

This commit is contained in:
Judd Vinet 2004-02-07 20:37:00 +00:00
parent 6d4c666a8e
commit 617b904b26
13 changed files with 3472 additions and 130 deletions

View file

@ -1,5 +1,11 @@
VERSION DESCRIPTION
-----------------------------------------------------------------------------
2.7.3 - makepkg not longer strips files with .exe or .dll extensions
- Added Aurelien's patch:
- proxy support (no authentication yet)
- HTTP/1.1 support
- an improved progress bar with transfer rates and ETA
- cleaned up warning output a bit
2.7.2 - Supressed "No such file" messages during stripping
- Removed extra newlines in /var/log/pacman.log
- Added a --noextract option to makepkg to skip source extraction

View file

@ -34,7 +34,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
PACVER = 2.7.2
PACVER = 2.7.3
TOPDIR = @srcdir@
SRCDIR = $(TOPDIR)/src/
@ -68,9 +68,9 @@ OBJECTS = $(OBJDIR)pacman.o \
$(OBJDIR)md5driver.o \
$(OBJDIR)rpmvercmp.o
all: ftplib pacman vercmp convertdb man
all: libftp.a pacman vercmp convertdb man
pacman: $(OBJECTS)
pacman: $(OBJECTS) libftp.a
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
vercmp: $(OBJDIR)vercmp.o $(OBJDIR)rpmvercmp.o
@ -91,7 +91,7 @@ man: $(MANSRC)pacman.8 \
dist: distclean
(cd ..; tar czvf pacman-$(PACVER).tar.gz pacman-$(PACVER))
ftplib:
libftp.a:
(cd libftp; make libftp.a)
install: pacman vercmp convertdb man
@ -112,5 +112,7 @@ clean:
distclean: clean
rm -f pacman convertdb vercmp
rm -f Makefile
rm -f config.h config.status config.log
# End of file

View file

@ -1,4 +1,4 @@
.TH pacman 8 "September 28, 2003" "pacman #VERSION#" ""
.TH pacman 8 "February 6, 2004" "pacman #VERSION#" ""
.SH NAME
pacman \- package manager utility
.SH SYNOPSIS
@ -100,6 +100,10 @@ diskspace, you can remove these packages by using the --clean option.
Display all the members for each package group specified. If no group
names are provided, all groups will be listed.
.TP
.B "\-l, \-\-list"
List all files in the specified repositories. Multiple repositories can
be specified on the command line.
.TP
.B "\-s, \-\-search <string>"
This will search each package in the package list for names or descriptions
that contains <string>.
@ -185,6 +189,7 @@ NoUpgrade = etc/fstab
[current]
Server = ftp://ftp.archlinux.org/current
Server = ftp://ftp.mirror.com/archlinux/current
Server = http://www.othermirror.com/arch/current
[custom]
Server = file:///home/pkgs
@ -201,6 +206,12 @@ Overrides the default location of the toplevel database directory. The default
Instructs pacman to ignore any upgrades for this package when performing a
\fB--sysupgrade\fP.
.TP
.B "ProxyServer = <host | ip>"
If set, pacman will use this proxy server for all ftp/http transfers.
.TP
.B "ProxyPort = <port>"
Use this to set a different port for your proxy server (default is 80).
.TP
.B "NoPassiveFtp"
Disables passive ftp connections when downloading packages. (aka Active Mode)
.TP

View file

@ -1,6 +1,10 @@
#
# /etc/pacman.conf
#
# NOTE: If you find a mirror that is geographically close to you, please
# move it to the top of the server list, so pacman will choose it
# first.
#
# See the pacman manpage for option directives
@ -12,6 +16,7 @@ LogFile = /var/log/pacman.log
NoUpgrade = etc/passwd etc/group etc/shadow
NoUpgrade = etc/fstab etc/raidtab
NoUpgrade = etc/rc.conf etc/rc.local
NoUpgrade = etc/modprobe.conf etc/modules.conf
NoUpgrade = etc/lilo.conf boot/grub/menu.lst
#IgnorePkg = lilo kernel
@ -20,6 +25,7 @@ NoUpgrade = etc/lilo.conf boot/grub/menu.lst
#
[current]
Server = ftp://ftp.archlinux.org/current
Server = ftp://ftp.archlinux.de/pub/archlinux/current
Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/current
Server = ftp://ftp.mpi-sb.mpg.de/pub/linux/mirror/ftp.ibiblio.org/pub/Linux/distributions/archlinux/current
Server = ftp://ftp.oit.unc.edu/pub/Linux/distributions/archlinux/current
@ -27,23 +33,24 @@ Server = ftp://ftp.tu-chemnitz.de/pub/linux/sunsite.unc-mirror/distributions/arc
Server = ftp://ftp.parrswood.net/Mirrors/ftp.archlinux.org/current
Server = ftp://ftp.kegep.tuc.gr/archlinux/current
Server = http://darkstar.ist.utl.pt/archlinux/current
Server = ftp://archlinux.creativa.cl/current
Server = ftp://gd.tuwien.ac.at/opsys/linux/archlinux/current
Server = ftp://saule.mintis.lt/pub/linux/current
Server = ftp://ftp.rez-gif.supelec.fr/pub/Linux/distrib/archlinux/current
Server = ftp://ftp.webtrek.com/pub/mirrors/archlinux/current
# Uncomment this block to access the EXTRA package set
#
[extra]
Server = ftp://ftp.archlinux.org/extra
Server = ftp://ftp.archlinux.de/pub/archlinux/extra
Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/extra
Server = ftp://ftp.webtrek.com/pub/mirrors/archlinux/extra
Server = ftp://ftp.mpi-sb.mpg.de/pub/linux/mirror/ftp.ibiblio.org/pub/Linux/distributions/archlinux/extra
Server = ftp://ftp.oit.unc.edu/pub/Linux/distributions/archlinux/extra
Server = ftp://ftp.tu-chemnitz.de/pub/linux/sunsite.unc-mirror/distributions/archlinux/extra
Server = ftp://ftp.parrswood.net/Mirrors/ftp.archlinux.org/extra
Server = ftp://ftp.kegep.tuc.gr/archlinux/extra
Server = http://darkstar.ist.utl.pt/archlinux/extra
Server = ftp://archlinux.creativa.cl/extra
Server = ftp://gd.tuwien.ac.at/opsys/linux/archlinux/extra
Server = ftp://saule.mintis.lt/pub/linux/extra
Server = ftp://ftp.rez-gif.supelec.fr/pub/Linux/distrib/archlinux/extra
@ -53,8 +60,8 @@ Server = ftp://ftp.rez-gif.supelec.fr/pub/Linux/distrib/archlinux/extra
#
#[release]
#Server = ftp://ftp.archlinux.org/release
#Server = ftp://ftp.archlinux.de/pub/archlinux/release
#Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/release
#Server = ftp://ftp.webtrek.com/pub/mirrors/archlinux/release
#Server = ftp://ftp.mpi-sb.mpg.de/pub/linux/mirror/ftp.ibiblio.org/pub/Linux/distributions/archlinux/release
#Server = ftp://ftp.oit.unc.edu/pub/Linux/distributions/archlinux/release
#Server = ftp://ftp.tu-chemnitz.de/pub/linux/sunsite.unc-mirror/distributions/archlinux/release
@ -69,13 +76,14 @@ Server = ftp://ftp.rez-gif.supelec.fr/pub/Linux/distrib/archlinux/extra
#
#[unstable]
#Server = ftp://ftp.archlinux.org/unstable
#Server = ftp://ftp.archlinux.de/pub/archlinux/unstable
#Server = ftp://ftp.ibiblio.org/pub/linux/distributions/archlinux/unstable
#Server = ftp://ftp.webtrek.com/pub/mirrors/archlinux/unstable
#Server = ftp://ftp.mpi-sb.mpg.de/pub/linux/mirror/ftp.ibiblio.org/pub/Linux/distributions/archlinux/unstable
#Server = ftp://ftp.oit.unc.edu/pub/Linux/distributions/archlinux/unstable
#Server = ftp://ftp.tu-chemnitz.de/pub/linux/sunsite.unc-mirror/distributions/archlinux/unstable
#Server = ftp://ftp.parrswood.net/Mirrors/ftp.archlinux.org/unstable
#Server = http://darkstar.ist.utl.pt/archlinux/unstable
#Server = ftp://archlinux.creativa.cl/unstable
#Server = ftp://gd.tuwien.ac.at/opsys/linux/archlinux/unstable
#Server = ftp://saule.mintis.lt/pub/linux/unstable
#Server = ftp://ftp.rez-gif.supelec.fr/pub/Linux/distrib/archlinux/unstable

View file

@ -1319,13 +1319,12 @@ GLOBALDEF void FtpQuit(netbuf *nControl)
*
* return 1 if connected, 0 if not
*/
GLOBALREF int HttpConnect(const char *host, netbuf **nControl)
GLOBALREF int HttpConnect(const char *host, unsigned short port, netbuf **nControl)
{
int sControl;
struct sockaddr_in sin;
struct hostent *phe;
struct servent *pse;
int on=1;
netbuf *ctrl;
char *lhost;
char *pnum;
@ -1337,14 +1336,18 @@ GLOBALREF int HttpConnect(const char *host, netbuf **nControl)
if (pnum == NULL)
{
#if defined(VMS)
sin.sin_port = htons(21);
sin.sin_port = htons(80);
#else
/* we pass a port variable instead (for use with proxies)
*
if ((pse = getservbyname("http","tcp")) == NULL)
{
perror("getservbyname");
return 0;
}
sin.sin_port = pse->s_port;
*/
sin.sin_port = htons(port);
#endif
}
else
@ -1374,13 +1377,6 @@ GLOBALREF int HttpConnect(const char *host, netbuf **nControl)
perror("socket");
return 0;
}
if (setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
{
perror("setsockopt");
net_close(sControl);
return 0;
}
if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
{
perror("connect");
@ -1448,13 +1444,14 @@ static int HttpSendCmd(const char *cmd, char expresp, netbuf *nControl)
*
* return 1 if successful, 0 otherwise
*/
static int HttpXfer(const char *localfile, const char *path,
static int HttpXfer(const char *localfile, const char *path, int *size,
netbuf *nControl, int typ, int mode)
{
int l,c;
char *dbuf;
FILE *local = NULL;
int rv=1;
int bytes = 0;
if (localfile != NULL)
{
@ -1487,13 +1484,18 @@ static int HttpXfer(const char *localfile, const char *path,
else
{
nControl->dir = FTPLIB_READ;
while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nControl)) > 0)
while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nControl)) > 0) {
if (fwrite(dbuf, 1, l, local) <= 0)
{
perror("localfile write");
rv = 0;
break;
}
bytes += l;
if(size && bytes >= *size) {
break;
}
}
}
free(dbuf);
fflush(local);
@ -1508,12 +1510,15 @@ static int HttpXfer(const char *localfile, const char *path,
*
* return 1 if successful, 0 otherwise
*/
GLOBALREF int HttpGet(const char *outputfile, const char *path, int *size,
netbuf *nControl)
GLOBALREF int HttpGet(const char *host, const char *outputfile, const char *path,
int *size, netbuf *nControl, unsigned int offset)
{
char buf[256];
sprintf(buf, "GET %s HTTP/1.0\r\n\r\n\r\n", path);
if(offset > 0)
sprintf(buf, "GET %s HTTP/1.1\r\nHost: %s\r\nRange: bytes=%d-\r\n\r\n", path, host, offset);
else
sprintf(buf, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", path, host);
if(!HttpSendCmd(buf,'2',nControl))
{
if (nControl->response[9] == '3')
@ -1537,12 +1542,16 @@ GLOBALREF int HttpGet(const char *outputfile, const char *path, int *size,
}
*buf = 0;
if (strstr(nControl->response,"Content-Length"))
{
sscanf(nControl->response,"Content-Length: %d",size);
if(offset > 0)
*size += offset;
}
if (strlen(nControl->response) == 0)
break;
}
return HttpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, FTPLIB_IMAGE);
return HttpXfer(outputfile, path, size, nControl, FTPLIB_FILE_READ, FTPLIB_IMAGE);
}
/*

View file

@ -119,9 +119,9 @@ GLOBALREF int FtpRename(const char *src, const char *dst, netbuf *nControl);
GLOBALREF int FtpDelete(const char *fnm, netbuf *nControl);
GLOBALREF void FtpQuit(netbuf *nControl);
GLOBALREF int HttpConnect(const char *host, netbuf **nControl);
GLOBALREF int HttpGet(const char *output, const char *path, int *size,
netbuf *nControl);
GLOBALREF int HttpConnect(const char *host, unsigned short port, netbuf **nControl);
GLOBALREF int HttpGet(const char *host, const char *output, const char *path,
int *size, netbuf *nControl, unsigned int offset);
GLOBALREF void HttpQuit(netbuf *nControl);
#ifdef __cplusplus

View file

@ -20,7 +20,7 @@
# USA.
#
myver='2.7.2'
myver='2.7.3'
usage() {
echo "gensync $myver"

View file

@ -20,7 +20,7 @@
# USA.
#
myver='2.7.2'
myver='2.7.3'
startdir=`pwd`
USE_COLOR="n"
@ -559,14 +559,13 @@ if [ -d pkg/usr/share ]; then
fi
# compress man pages
if [ -d pkg/usr/man ]; then
msg "Compressing man pages..."
for i in `find pkg/usr/man -type f`; do
ext=`echo $i | sed 's|.*\.||g'`
fn=`echo $i | sed 's|.*/||g'`
for i in `find pkg/{usr{,/local},opt/*}/man -type f 2>/dev/null`; do
ext=${i##*.}
fn=${i##*/}
if [ "$ext" != "gz" ]; then
# update symlinks to this manpage
for ln in `find pkg/usr/man -lname "$fn"`; do
for ln in `find pkg/{usr{,/local},opt/*}/man -lname "$fn" 2>/dev/null`; do
rm -f $ln
ln -sf ${fn}.gz ${ln}.gz
done
@ -574,16 +573,19 @@ if [ -d pkg/usr/man ]; then
gzip -9 $i
fi
done
fi
cd $startdir
# strip binaries
if [ "$NOSTRIP" = "0" ]; then
msg "Stripping debugging symbols from libraries..."
find pkg/{,usr,usr/local,opt/*}/lib -type f -exec /usr/bin/strip --strip-debug '{}' \; 2>&1 | grep -v "No such file"
find pkg/{,usr,usr/local,opt/*}/lib -type f -not -name "*.dll" -not -name "*.exe" \
-exec /usr/bin/strip --strip-debug '{}' \; 2>&1 \
| grep -v "No such file" | grep -v "format not recognized"
msg "Stripping symbols from binaries..."
find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -exec /usr/bin/strip '{}' \; 2>&1 | grep -v "No such file"
find pkg/{,usr,usr/local,opt/*}/{bin,sbin} -type f -not -name "*.dll" -not -name "*.exe" \
-exec /usr/bin/strip '{}' \; 2>&1 \
| grep -v "No such file" | grep -v "format not recognized"
fi
# get some package meta info

View file

@ -21,7 +21,7 @@
#
toplevel=`pwd`
version="2.7.2"
version="2.7.3"
usage() {
echo "makeworld version $version"

View file

@ -78,6 +78,8 @@ unsigned short pmo_group = 0;
/* configuration file options */
char *pmo_dbpath = NULL;
char *pmo_logfile = NULL;
char *pmo_proxyhost = NULL;
unsigned short pmo_proxyport = 80;
PMList *pmo_noupgrade = NULL;
PMList *pmo_ignorepkg = NULL;
unsigned short pmo_usesyslog = 0;
@ -96,6 +98,7 @@ char *lckfile = "/tmp/pacman.lck";
char *workfile = NULL;
enum {READ_ONLY, READ_WRITE} pm_access;
int maxcols = 80;
int neednl = 0; /* for cleaner message output */
int main(int argc, char *argv[])
{
@ -133,7 +136,7 @@ int main(int argc, char *argv[])
/* check for permission */
pm_access = READ_ONLY;
if(pmo_op != PM_MAIN && pmo_op != PM_QUERY && pmo_op != PM_DEPTEST) {
if(pmo_op == PM_SYNC && !pmo_s_sync && (pmo_s_search || pmo_group)) {
if(pmo_op == PM_SYNC && !pmo_s_sync && (pmo_s_search || pmo_group || pmo_q_list)) {
/* special case: PM_SYNC can be used w/ pmo_s_search by any user */
} else {
if(geteuid() != 0) {
@ -456,6 +459,37 @@ int pacman_sync(pacdb_t *db, PMList *targets)
FREELIST(pkg);
}
FREELIST(groups);
} else if(pmo_q_list) {
PMList *reps = NULL;
int found;
if(targets) {
for(i = targets; i; i = i->next) {
reps = list_add(reps, strdup(i->data));
}
} else {
for(i = pmc_syncs; i; i = i->next) {
reps = list_add(reps, strdup(((sync_t *)i->data)->treename));
}
}
for(i = reps; i; i = i->next) {
found = 0;
for(j = databases; j; j = j->next) {
dbsync_t *dbs = (dbsync_t *)j->data;
if(!strcmp(dbs->sync->treename, i->data)) {
for(k = dbs->pkgcache; k; k = k->next) {
pkginfo_t *pkg = (pkginfo_t*)k->data;
printf("%s %s %s\n", dbs->sync->treename, pkg->name, pkg->version);
}
found = 1;
}
}
if(!found) {
printf("Repository \"%s\" was not found.\n", (char *)i->data);
allgood = 0;
break;
}
}
FREELIST(reps);
} else if(pmo_s_upgrade) {
int newer = 0;
int ignore = 0;
@ -687,7 +721,7 @@ int pacman_sync(pacdb_t *db, PMList *targets)
}
}
if(allgood && !pmo_s_search) {
if(allgood && !(pmo_s_search || pmo_q_list)) {
/* check for inter-conflicts and whatnot */
if(!pmo_nodeps && !pmo_s_downloadonly) {
int errorout = 0;
@ -1132,7 +1166,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
fflush(stdout);
for(targ = targets; targ; targ = targ->next) {
/* Populate the package struct */
vprint("reading %s\n", (char*)targ->data);
vprint("reading %s... ", (char*)targ->data);
info = load_pkg((char*)targ->data, 0);
if(info == NULL) {
return(1);
@ -1141,11 +1175,28 @@ int pacman_add(pacdb_t *db, PMList *targets)
/* only upgrade/install this package if it is already installed and at a lesser version */
pkginfo_t *dummy = db_scan(db, info->name, INFRQ_DESC);
if(dummy == NULL || rpmvercmp(dummy->version, info->version) >= 0) {
vprint("not installed or lesser version\n");
FREEPKG(info);
FREEPKG(dummy);
continue;
}
FREEPKG(dummy);
}
/* check if an older version of said package is already in alltargs.
* if so, replace it in the list */
for(j = alltargs, k = filenames; j && j->data && k; j = j->next, k = k->next) {
pkginfo_t *pkg = (pkginfo_t*)j->data;
if(!strcmp(pkg->name, info->name)) {
if(rpmvercmp(pkg->version, info->version) < 0) {
vprint("replacing older version in target list. ");
FREEPKG(j->data);
j->data = info;
FREE(k->data);
k->data = strdup(targ->data);
}
}
}
vprint("done\n");
alltargs = list_add(alltargs, info);
filenames = list_add(filenames, strdup(targ->data));
}
@ -1301,6 +1352,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
int retcode;
printf("upgrading %s... ", info->name);
neednl = 1;
/* we'll need the full record for backup checks later */
oldpkg = db_scan(db, info->name, INFRQ_ALL);
@ -1326,6 +1378,7 @@ int pacman_add(pacdb_t *db, PMList *targets)
}
if(!pmo_upgrade) {
printf("installing %s... ", info->name);
neednl = 1;
}
fflush(stdout);
@ -1711,6 +1764,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
if(!pmo_upgrade) {
printf("removing %s... ", info->name);
neednl = 1;
fflush(stdout);
/* run the pre-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);
@ -1764,7 +1818,7 @@ int pacman_remove(pacdb_t *db, PMList *targets)
}
}
} else {
vprint(" unlinking %s\n", line);
/*vprint(" unlinking %s\n", line);*/
if(unlink(line)) {
perror("cannot remove file");
}
@ -2845,8 +2899,30 @@ int parseconfig(char *configfile)
strncpy(pmo_dbpath, ptr, PATH_MAX);
vprint("config: dbpath: %s\n", pmo_dbpath);
} else if (!strcmp(key, "LOGFILE")) {
if(pmo_logfile) {
FREE(pmo_logfile);
}
pmo_logfile = strndup(ptr, PATH_MAX);
vprint("config: log file: %s\n", pmo_logfile);
} else if (!strcmp(key, "PROXYSERVER")) {
char *p;
if(pmo_proxyhost) {
FREE(pmo_proxyhost);
}
p = strstr(ptr, "://");
if(p) {
p += 3;
if(p == NULL || *p == '\0') {
fprintf(stderr, "config: line %d: bad server location\n", linenum);
return(1);
}
ptr = p;
}
pmo_proxyhost = strndup(ptr, PATH_MAX);
vprint("config: proxyserver: %s\n", pmo_proxyhost);
} else if (!strcmp(key, "PROXYPORT")) {
pmo_proxyport = (unsigned short)atoi(ptr);
vprint("config: proxyport: %u\n", pmo_proxyport);
} else {
fprintf(stderr, "config: line %d: syntax error\n", linenum);
return(1);
@ -2973,6 +3049,7 @@ void usage(int op, char *myname)
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(" -l, --list list all packages belonging to the specified repository\n");
printf(" -s, --search search sync database 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");
@ -3019,6 +3096,10 @@ void logaction(FILE *fp, char *fmt, ...)
vsnprintf(msg, 1024, fmt, args);
va_end(args);
if(fp) {
if(neednl) {
fprintf(fp, "\n");
neednl = 0;
}
fprintf(fp, "%s\n", msg);
fflush(fp);
}
@ -3116,12 +3197,18 @@ void cleanup(int signum)
FREELIST(pmo_ignorepkg);
FREE(pmo_root);
FREE(pmo_dbpath);
FREE(pmo_logfile);
FREE(pmo_proxyhost);
FREELIST(pm_targets);
/* this is segfaulting... quick fix for now
FREELISTPKGS(pm_packages);*/
if(signum) {
printf("\n");
}
exit(signum);
}

3145
src/pacman.c~ Normal file

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@
#define _PAC_PACMAN_H
#ifndef PACVER
#define PACVER "2.7.2"
#define PACVER "2.7.3"
#endif
#ifndef PKGDIR

View file

@ -25,6 +25,7 @@
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <ftplib.h>
/* pacman */
#include "list.h"
@ -34,13 +35,21 @@
#include "pacsync.h"
#include "pacman.h"
/* progress bar */
static int log_progress(netbuf *ctl, int xfered, void *arg);
static char sync_fnm[25];
static int offset;
static struct timeval t0, t;
static float rate;
static int xfered1;
static unsigned char eta_h, eta_m, eta_s;
/* pacman options */
extern char *pmo_root;
extern char *pmo_dbpath;
extern char *pmo_proxyhost;
extern unsigned short pmo_proxyport;
extern unsigned short pmo_nopassiveftp;
/* sync servers */
@ -112,8 +121,9 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
for(i = servers; i && !done; i = i->next) {
server_t *server = (server_t*)i->data;
if(!strcmp(server->protocol, "ftp")) {
if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
FtpInit();
vprint("Connecting to %s:21\n", server->server);
if(!FtpConnect(server->server, &control)) {
fprintf(stderr, "error: cannot connect to %s\n", server->server);
continue;
@ -135,9 +145,15 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
} else {
vprint("FTP passive mode not set\n");
}
} else if(!strcmp(server->protocol, "http")) {
if(!HttpConnect(server->server, &control)) {
fprintf(stderr, "error: cannot connect to %s\n", server->server);
/*} else if(!strcmp(server->protocol, "http") || (pmo_proxyhost && !strcmp(server->protocol, "ftp"))) {*/
} else if(!strcmp(server->protocol, "http") || pmo_proxyhost) {
char *host;
unsigned port;
host = (pmo_proxyhost) ? pmo_proxyhost : server->server;
port = (pmo_proxyhost) ? pmo_proxyport : 80;
vprint("Connecting to %s:%u\n", host, port);
if(!HttpConnect(host, port, &control)) {
fprintf(stderr, "error: cannot connect to %s\n", host);
continue;
}
}
@ -155,6 +171,7 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
char output[PATH_MAX];
int j, filedone = 0;
char *fn = (char*)lp->data;
char *ptr;
struct stat st;
if(is_in(fn, complete)) {
@ -163,13 +180,31 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
snprintf(output, PATH_MAX, "%s/%s.part", localpath, fn);
strncpy(sync_fnm, fn, 24);
/* drop filename extension */
ptr = strstr(fn, ".db.tar.gz");
if(ptr && (ptr-fn) < 24) {
sync_fnm[ptr-fn] = '\0';
}
ptr = strstr(fn, ".pkg.tar.gz");
if(ptr && (ptr-fn) < 24) {
sync_fnm[ptr-fn] = '\0';
}
for(j = strlen(sync_fnm); j < 24; j++) {
sync_fnm[j] = ' ';
}
sync_fnm[24] = '\0';
offset = 0;
if(!strcmp(server->protocol, "ftp")) {
/* ETA setup */
gettimeofday(&t0, NULL);
t = t0;
rate = 0;
xfered1 = 0;
eta_h = 0;
eta_m = 0;
eta_s = 0;
if(!strcmp(server->protocol, "ftp") && !pmo_proxyhost) {
if(!FtpSize(fn, &fsz, FTPLIB_IMAGE, control)) {
fprintf(stderr, "warning: failed to get filesize for %s\n", fn);
}
@ -189,18 +224,21 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
} else {
filedone = 1;
}
} else if(!strcmp(server->protocol, "http")) {
/*} else if(!strcmp(server->protocol, "http") || (pmo_proxyhost && !strcmp(server->protocol, "ftp"))) {*/
} else if(!strcmp(server->protocol, "http") || pmo_proxyhost) {
char src[PATH_MAX];
if(!stat(output, &st)) {
/* no resume support yet */
unlink(output);
offset = (int)st.st_size;
}
if(!pmo_proxyhost) {
snprintf(src, PATH_MAX, "%s%s", server->path, fn);
if(!HttpGet(output, src, &fsz, control)) {
} else {
snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn);
}
if(!HttpGet(server->server, output, src, &fsz, control, offset)) {
fprintf(stderr, "\nfailed downloading %s from %s: %s\n",
fn, server->server, FtpLastResponse(control));
/* no resume support yet */
unlink(output);
/* we leave the partially downloaded file in place so it can be resumed later */
} else {
filedone = 1;
}
@ -223,10 +261,10 @@ int downloadfiles(PMList *servers, char *localpath, PMList *files)
printf(" %s [", sync_fnm);
strncpy(out, server->path, 33);
printf("%s", out);
for(j = strlen(out); j < maxcols-44; j++) {
for(j = strlen(out); j < maxcols-64; j++) {
printf(" ");
}
fputs("] 100% | LOCAL\n", stdout);
fputs("] 100% | LOCAL |", stdout);
} else {
log_progress(control, fsz-offset, &fsz);
}
@ -257,13 +295,47 @@ static int log_progress(netbuf *ctl, int xfered, void *arg)
int fsz = *(int*)arg;
int pct = ((float)(xfered+offset) / fsz) * 100;
int i, cur;
struct timeval t1;
float timediff;
gettimeofday(&t1, NULL);
if(xfered+offset == fsz) {
t = t0;
}
timediff = t1.tv_sec-t.tv_sec + (float)(t1.tv_usec-t.tv_usec) / 1000000;
if(xfered+offset == fsz) {
/* average download rate */
rate = xfered / (timediff * 1024);
/* total download time */
eta_s = (int)timediff;
eta_h = eta_s / 3600;
eta_s -= eta_h * 3600;
eta_m = eta_s / 60;
eta_s -= eta_m * 60;
} else if(timediff > 1) {
/* we avoid computing the rate & ETA on too small periods of time, so that
results are more significant */
rate = (xfered-xfered1) / (timediff * 1024);
xfered1 = xfered;
gettimeofday(&t, NULL);
eta_s = (fsz-(xfered+offset)) / (rate * 1024);
eta_h = eta_s / 3600;
eta_s -= eta_h * 3600;
eta_m = eta_s / 60;
eta_s -= eta_m * 60;
}
printf(" %s [", sync_fnm);
cur = (int)((maxcols-44)*pct/100);
for(i = 0; i < maxcols-44; i++) {
cur = (int)((maxcols-64)*pct/100);
for(i = 0; i < maxcols-64; i++) {
(i < cur) ? printf("#") : printf(" ");
}
printf("] %3d%% | %6dK\r", pct, ((xfered+offset)/1024));
if(rate > 1000) {
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);
}
fflush(stdout);
return(1);
}