Reset errno before opening archive

Set errno to 0 at the start of _alpm_open_archive as it is not set when
archive_read_open_fd fails.  This can result in _alpm_pkg_load_internal
thinking errno == ENOENT and setting the wrong pm_errno. e.g.

Before:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot find the given file.

After:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot open the given file.

Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2012-02-11 16:17:59 +10:00 committed by Dan McGee
parent 8741551dc9
commit 7a3f59cd66

View file

@ -227,6 +227,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path,
{ {
int fd; int fd;
size_t bufsize = ALPM_BUFFER_SIZE; size_t bufsize = ALPM_BUFFER_SIZE;
errno = 0;
if((*archive = archive_read_new()) == NULL) { if((*archive = archive_read_new()) == NULL) {
RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1); RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1);