Return more useful error codes on package open failures

Failure isn't always due to the package file location not existing;
permission issues can also play a part on something like a FUSE-based
filesystem inaccessible to root.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2012-04-07 11:29:11 -05:00
parent cb5ae428b6
commit 42d408e0c2
2 changed files with 13 additions and 2 deletions

View file

@ -319,7 +319,14 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
/* attempt to access the package file, ensure it exists */ /* attempt to access the package file, ensure it exists */
if(_alpm_access(handle, NULL, pkgfile, R_OK) != 0) { if(_alpm_access(handle, NULL, pkgfile, R_OK) != 0) {
RET_ERR(handle, ALPM_ERR_PKG_NOT_FOUND, -1); if(errno == ENOENT) {
handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
} else if(errno == EACCES) {
handle->pm_errno = ALPM_ERR_BADPERMS;
} else {
handle->pm_errno = ALPM_ERR_PKG_OPEN;
}
return -1;
} }
/* can we get away with skipping checksums? */ /* can we get away with skipping checksums? */
@ -407,6 +414,10 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
if(fd < 0) { if(fd < 0) {
if(errno == ENOENT) { if(errno == ENOENT) {
handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND; handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
} else if(errno == EACCES) {
handle->pm_errno = ALPM_ERR_BADPERMS;
} else {
handle->pm_errno = ALPM_ERR_PKG_OPEN;
} }
return NULL; return NULL;
} }

View file

@ -41,7 +41,7 @@ const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
case ALPM_ERR_SYSTEM: case ALPM_ERR_SYSTEM:
return _("unexpected system error"); return _("unexpected system error");
case ALPM_ERR_BADPERMS: case ALPM_ERR_BADPERMS:
return _("insufficient privileges"); return _("permission denied");
case ALPM_ERR_NOT_A_FILE: case ALPM_ERR_NOT_A_FILE:
return _("could not find or read file"); return _("could not find or read file");
case ALPM_ERR_NOT_A_DIR: case ALPM_ERR_NOT_A_DIR: