From 20aa17c276c35e08c7a8e2aa20410b99a20f8129 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 23 Sep 2009 19:11:34 -0500 Subject: repo-add: make sure we get size of target file If the package we were adding was a symlink, we stuck the symlink size in the database rather than the size of the file it referred to. Whoops! Signed-off-by: Dan McGee --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 1e9ab35b..9f3445dd 100644 --- a/configure.ac +++ b/configure.ac @@ -184,11 +184,11 @@ GCC_VISIBILITY_CC GCC_GNU89_INLINE_CC # Host-dependant definitions -SIZECMD="stat -c %s" +SIZECMD="stat -L -c %s" SEDINPLACE="sed -i" case "${host_os}" in *bsd*) - SIZECMD="stat -f %z" + SIZECMD="stat -L -f %z" SEDINPLACE="sed -i ''" ;; cygwin*) @@ -197,7 +197,7 @@ case "${host_os}" in ;; darwin*) host_os_darwin=yes - SIZECMD="/usr/bin/stat -f %z" + SIZECMD="/usr/bin/stat -L -f %z" SEDINPLACE="/usr/bin/sed -i ''" ;; esac -- cgit v1.2.3-70-g09d2 From 7f14f185a2d05650e1f99f4ec40d60b597e8b0c7 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 23 Sep 2009 21:15:53 -0500 Subject: repo-remove: create empty DB when all packages are removed Rather than creating no database at all, create an empty zipped tar archive in its place. This keeps the download side of repositories a bit more sane as a DB will always exist, and pacman handles this empty case just fine. For this to be fully transparent, we also need to make sure repo-add and repo-remove accept an empty "DB" as an argument, which in reality is a completely void of files .tar.{gz,bz2,xz} archive. Signed-off-by: Dan McGee --- scripts/repo-add.sh.in | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index a1e5f7f4..c8380c4e 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -306,9 +306,14 @@ check_repo_db() fi if [ -f "$REPO_DB_FILE" ]; then - if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' 2>&1 >/dev/null; then - error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" - exit 1 + # there are two situations we can have here- a DB with some entries, + # or a DB with no contents at all. + if ! bsdtar -tqf "$REPO_DB_FILE" '*/desc' >/dev/null 2>&1; then + # check empty case + if [ -n "$(bsdtar -tqf "$REPO_DB_FILE" '*' 2>/dev/null)" ]; then + error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" + exit 1 + fi fi msg "$(gettext "Extracting database to a temporary location...")" bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir" @@ -484,8 +489,9 @@ if [ $success -eq 1 ]; then if [ -n "$(ls)" ]; then bsdtar -c${TAR_OPT}f "$filename" * else - # the database will be moved to .old below, and there will be no new one to replace it - error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE" + # we have no packages remaining? zip up some emptyness + warning "$(gettext "No packages remain, creating empty database.")" + bsdtar -c${TAR_OPT}f "$filename" -T /dev/null fi cd "$startdir" -- cgit v1.2.3-70-g09d2 From 20392c0a025d01128eb78c6656db7c15b3fbcd89 Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Tue, 29 Sep 2009 19:19:54 +0200 Subject: dload : fix infinite download (big type mistake) fetchIO_read returns -1 in case of error, and the return type is ssize_t, not size_t ! So we converted -1 to an unsigned, which led to huge file write. The rest is just changing the error return a bit. Signed-off-by: Xavier Chantry Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 4695731a..10be5e9d 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -100,6 +100,15 @@ static struct url *url_for_string(const char *url) return(ret); } +static const char *gethost(struct url *fileurl) +{ + const char *host = _("disk"); + if(strcmp(SCHEME_FILE, fileurl->scheme) != 0) { + host = fileurl->host; + } + return(host); +} + static int download_internal(const char *url, const char *localpath, time_t mtimeold, time_t *mtimenew) { fetchIO *dlf = NULL; @@ -107,7 +116,8 @@ static int download_internal(const char *url, const char *localpath, struct url_stat ust; struct stat st; int chk_resume = 0, ret = 0; - size_t dl_thisfile = 0, nread = 0; + size_t dl_thisfile = 0; + ssize_t nread = 0; char *tempfile, *destfile, *filename; struct sigaction new_action, old_action; struct url *fileurl = url_for_string(url); @@ -170,13 +180,9 @@ static int download_internal(const char *url, const char *localpath, } if(fetchLastErrCode != 0 || dlf == NULL) { - const char *host = _("disk"); - if(strcmp(SCHEME_FILE, fileurl->scheme) != 0) { - host = fileurl->host; - } pm_errno = PM_ERR_LIBFETCH; _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s : %s\n"), - filename, host, fetchLastErrString); + filename, gethost(fileurl), fetchLastErrString); ret = -1; goto cleanup; } else { @@ -231,8 +237,17 @@ static int download_internal(const char *url, const char *localpath, } /* did the transfer complete normally? */ + if (nread == -1) { + /* not PM_ERR_LIBFETCH here because libfetch error string might be empty */ + pm_errno = PM_ERR_RETRIEVE; + _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s\n"), + filename, gethost(fileurl)); + ret = -1; + goto cleanup; + } + if (ust.size != -1 && dl_thisfile < ust.size) { - pm_errno = PM_ERR_LIBFETCH; + pm_errno = PM_ERR_RETRIEVE; _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"), filename, (intmax_t)dl_thisfile, (intmax_t)ust.size); ret = -1; -- cgit v1.2.3-70-g09d2