* Added archive verification when loading package metadata for -u and -A
operations (now aborts on a corrupt archive) * Fixed the pm_fprintf newline error that was plaguing us. It seems a line resetting 'neednl' was removed a while back (by me). This causes all the output errors we've been seeing
This commit is contained in:
parent
e3c7e92f10
commit
b2da4b4234
3 changed files with 31 additions and 20 deletions
|
@ -237,7 +237,7 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output)
|
||||||
pmpkg_t *_alpm_pkg_load(char *pkgfile)
|
pmpkg_t *_alpm_pkg_load(char *pkgfile)
|
||||||
{
|
{
|
||||||
char *expath;
|
char *expath;
|
||||||
int i;
|
int ret = ARCHIVE_OK;
|
||||||
int config = 0;
|
int config = 0;
|
||||||
int filelist = 0;
|
int filelist = 0;
|
||||||
int scriptcheck = 0;
|
int scriptcheck = 0;
|
||||||
|
@ -254,31 +254,35 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile)
|
||||||
RET_ERR(PM_ERR_WRONG_ARGS, NULL);
|
RET_ERR(PM_ERR_WRONG_ARGS, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((archive = archive_read_new ()) == NULL)
|
if((archive = archive_read_new()) == NULL) {
|
||||||
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
|
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
archive_read_support_compression_all (archive);
|
archive_read_support_compression_all(archive);
|
||||||
archive_read_support_format_all (archive);
|
archive_read_support_format_all(archive);
|
||||||
|
|
||||||
if (archive_read_open_file (archive, pkgfile, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
|
if (archive_read_open_file(archive, pkgfile, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
|
||||||
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
info = _alpm_pkg_new(NULL, NULL);
|
info = _alpm_pkg_new(NULL, NULL);
|
||||||
if(info == NULL) {
|
if(info == NULL) {
|
||||||
archive_read_finish (archive);
|
archive_read_finish(archive);
|
||||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
RET_ERR(PM_ERR_MEMORY, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO there is no reason to make temp files to read
|
/* TODO there is no reason to make temp files to read
|
||||||
* from a libarchive archive, it can be done by reading
|
* from a libarchive archive, it can be done by reading
|
||||||
* directly from the archive */
|
* directly from the archive
|
||||||
for(i = 0; archive_read_next_header (archive, &entry) == ARCHIVE_OK; i++) {
|
* See: archive_read_data_into_buffer
|
||||||
const char *entry_name = archive_entry_pathname(entry);
|
* requires changes 'parse_descfile' as well
|
||||||
|
* */
|
||||||
|
|
||||||
if(config && filelist && scriptcheck) {
|
/* Read through the entire archive for metadata. We will continue reading
|
||||||
/* we have everything we need */
|
* even if all metadata is found, to verify the integrity of the archive in
|
||||||
break;
|
* full */
|
||||||
}
|
while((ret = archive_read_next_header (archive, &entry)) == ARCHIVE_OK) {
|
||||||
|
const char *entry_name = archive_entry_pathname(entry);
|
||||||
|
|
||||||
if(strcmp(entry_name, ".PKGINFO") == 0) {
|
if(strcmp(entry_name, ".PKGINFO") == 0) {
|
||||||
/* extract this file into /tmp. it has info for us */
|
/* extract this file into /tmp. it has info for us */
|
||||||
|
@ -343,18 +347,25 @@ pmpkg_t *_alpm_pkg_load(char *pkgfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(archive_read_data_skip(archive)) {
|
if(archive_read_data_skip(archive)) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("bad package file in %s"), pkgfile);
|
_alpm_log(PM_LOG_ERROR, _("error while reading package: %s"), archive_error_string(archive));
|
||||||
|
pm_errno = PM_ERR_LIBARCHIVE_ERROR;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
expath = NULL;
|
expath = NULL;
|
||||||
}
|
}
|
||||||
archive_read_finish(archive);
|
if(ret != ARCHIVE_EOF) { /* An error occured */
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("error while reading package: %s"), archive_error_string(archive));
|
||||||
|
pm_errno = PM_ERR_LIBARCHIVE_ERROR;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if(!config) {
|
if(!config) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("missing package info file in %s"), pkgfile);
|
_alpm_log(PM_LOG_ERROR, _("missing package metadata"), pkgfile);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
archive_read_finish(archive);
|
||||||
|
|
||||||
if(!filelist) {
|
if(!filelist) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("missing package filelist in %s, generating one"), pkgfile);
|
_alpm_log(PM_LOG_ERROR, _("missing package filelist in %s, generating one"), pkgfile);
|
||||||
info->files = all_files;
|
info->files = all_files;
|
||||||
|
|
|
@ -77,7 +77,7 @@ int pacman_add(alpm_list_t *targets)
|
||||||
for(i = targets; i; i = i->next) {
|
for(i = targets; i; i = i->next) {
|
||||||
if(alpm_trans_addtarget(i->data) == -1) {
|
if(alpm_trans_addtarget(i->data) == -1) {
|
||||||
MSG(NL, "\n");
|
MSG(NL, "\n");
|
||||||
ERR(NL, _("failed to add target '%s' (%s)\n"), (char *)i->data, alpm_strerror(pm_errno));
|
ERR(NL, _("failed to add target '%s' (%s)"), (char *)i->data, alpm_strerror(pm_errno));
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,19 +126,19 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(file, str);
|
fprintf(file, str);
|
||||||
|
|
||||||
if(needpad == 1) {
|
if(needpad == 1) {
|
||||||
unsigned int i, cols = getcols();
|
unsigned int i, cols = getcols();
|
||||||
for(i=len; i < cols; ++i) {
|
for(i=len; i < cols; ++i) {
|
||||||
fprintf(file, " ");
|
fprintf(file, " ");
|
||||||
}
|
}
|
||||||
if(neednl == 1) {
|
if(neednl == 1 && line == NL) {
|
||||||
fprintf(file, "\n");
|
fprintf(file, "\n");
|
||||||
neednl = 0;
|
neednl = 0;
|
||||||
} else {
|
|
||||||
neednl = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fflush(file);
|
fflush(file);
|
||||||
|
neednl = (str[strlen(str)-1] == '\n') ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check verbosity option and, if set, print the
|
/* Check verbosity option and, if set, print the
|
||||||
|
|
Loading…
Add table
Reference in a new issue