[pacman-dev] [PATCH] Do not continuously try to open an invalid database
If you manage to download a bad database (e.g. an html file when behind a proxy or with a badly configured webserver), pacman makes sure you know about it. Here is some example output: error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format I don't know how many times that gets printed because it goes beyond my scrollback buffer. Flag a database that we can "open" and "fstat" but not read from as invalid to avoid this. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/be_sync.c | 3 +++ lib/libalpm/util.c | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 06f509a6..46959298 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -486,6 +486,9 @@ static int sync_db_populate(alpm_db_t *db) fd = _alpm_open_archive(db->handle, dbpath, &buf, &archive, ALPM_ERR_DB_OPEN); if(fd < 0) { + if(db->handle->pm_errno == ALPM_ERR_DB_INVALID) { + db->status &= DB_STATUS_INVALID; + } return -1; } est_count = estimate_package_count(&buf, archive); diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 35fc7f41..0fb9bb6d 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -268,6 +268,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path, if(archive_read_open_fd(*archive, fd, bufsize) != ARCHIVE_OK) { _alpm_log(handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, archive_error_string(*archive)); + error = ALPM_ERR_DB_INVALID; goto error; } -- 2.12.2
On 05/09/17 at 11:38am, Allan McRae wrote:
If you manage to download a bad database (e.g. an html file when behind a proxy or with a badly configured webserver), pacman makes sure you know about it. Here is some example output:
error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format error: could not open file /var/lib/pacman/sync/extra.db: Unrecognized archive format
I don't know how many times that gets printed because it goes beyond my scrollback buffer.
Flag a database that we can "open" and "fstat" but not read from as invalid to avoid this.
Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/be_sync.c | 3 +++ lib/libalpm/util.c | 1 + 2 files changed, 4 insertions(+)
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 06f509a6..46959298 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -486,6 +486,9 @@ static int sync_db_populate(alpm_db_t *db) fd = _alpm_open_archive(db->handle, dbpath, &buf, &archive, ALPM_ERR_DB_OPEN); if(fd < 0) { + if(db->handle->pm_errno == ALPM_ERR_DB_INVALID) { + db->status &= DB_STATUS_INVALID; + }
ACK
return -1; } est_count = estimate_package_count(&buf, archive); diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 35fc7f41..0fb9bb6d 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -268,6 +268,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path, if(archive_read_open_fd(*archive, fd, bufsize) != ARCHIVE_OK) { _alpm_log(handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, archive_error_string(*archive)); + error = ALPM_ERR_DB_INVALID;
We shouldn't be using a db-specific error here. _alpm_open_archive is used for packages as well. If we want to differentiate between open and format failures we'll either have to take a second error code or set return values and let the caller set the handle error based on that. I think the ALPM_ERR_*_OPEN codes we're using for this function now are fine, though.
goto error; }
-- 2.12.2
participants (2)
-
Allan McRae
-
Andrew Gregory