mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-08 12:28:00 -05:00
Rework the alpm_unpack functions
Add support to extract a list of entries Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
471b1fa543
commit
14ab02e289
@ -245,7 +245,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
|||||||
|
|
||||||
/* uncompress the sync database */
|
/* uncompress the sync database */
|
||||||
checkdbdir(db);
|
checkdbdir(db);
|
||||||
ret = _alpm_unpack(dbfilepath, syncdbpath, NULL);
|
ret = _alpm_unpack(dbfilepath, syncdbpath, NULL, 0);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
free(dbfilepath);
|
free(dbfilepath);
|
||||||
RET_ERR(PM_ERR_SYSTEM, -1);
|
RET_ERR(PM_ERR_SYSTEM, -1);
|
||||||
|
@ -368,7 +368,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
|
|||||||
/* either extract or copy the scriptlet */
|
/* either extract or copy the scriptlet */
|
||||||
snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir);
|
snprintf(scriptfn, PATH_MAX, "%s/.INSTALL", tmpdir);
|
||||||
if(!strcmp(script, "pre_upgrade") || !strcmp(script, "pre_install")) {
|
if(!strcmp(script, "pre_upgrade") || !strcmp(script, "pre_install")) {
|
||||||
if(_alpm_unpack(installfn, tmpdir, ".INSTALL")) {
|
if(_alpm_unpack_single(installfn, tmpdir, ".INSTALL")) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -238,14 +238,38 @@ int _alpm_lckrm()
|
|||||||
/* Compression functions */
|
/* Compression functions */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unpack a specific file or all files in an archive.
|
* @brief Unpack a specific file in an archive.
|
||||||
*
|
*
|
||||||
* @param archive the archive to unpack
|
* @param archive the archive to unpack
|
||||||
* @param prefix where to extract the files
|
* @param prefix where to extract the files
|
||||||
* @param fn a file within the archive to unpack or NULL for all
|
* @param fn a file within the archive to unpack
|
||||||
* @return 0 on success, 1 on failure
|
* @return 0 on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn)
|
||||||
|
{
|
||||||
|
alpm_list_t *list = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
if(fn == NULL) {
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
list = alpm_list_add(list, (void *)fn);
|
||||||
|
ret = _alpm_unpack(archive, prefix, list, 1);
|
||||||
|
alpm_list_free(list);
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unpack a list of files in an archive.
|
||||||
|
*
|
||||||
|
* @param archive the archive to unpack
|
||||||
|
* @param prefix where to extract the files
|
||||||
|
* @param list a list of files within the archive to unpack or
|
||||||
|
* NULL for all
|
||||||
|
* @param breakfirst break after the first entry found
|
||||||
|
*
|
||||||
|
* @return 0 on success, 1 on failure
|
||||||
|
*/
|
||||||
|
int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
mode_t oldmask;
|
mode_t oldmask;
|
||||||
@ -298,14 +322,23 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
|||||||
archive_entry_set_perm(entry, 0755);
|
archive_entry_set_perm(entry, 0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If a specific file was requested skip entries that don't match. */
|
/* If specific files were requested, skip entries that don't match. */
|
||||||
if (fn && strcmp(fn, entryname)) {
|
if(list) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "skipping: %s\n", entryname);
|
char *prefix = strdup(entryname);
|
||||||
if (archive_read_data_skip(_archive) != ARCHIVE_OK) {
|
char *p = strstr(prefix,"/");
|
||||||
ret = 1;
|
if(p) {
|
||||||
goto cleanup;
|
*(p+1) = '\0';
|
||||||
|
}
|
||||||
|
char *found = alpm_list_find_str(list, prefix);
|
||||||
|
free(prefix);
|
||||||
|
if(!found) {
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "skipping: %s\n", entryname);
|
||||||
|
if (archive_read_data_skip(_archive) != ARCHIVE_OK) {
|
||||||
|
ret = 1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the archive entry. */
|
/* Extract the archive entry. */
|
||||||
@ -321,7 +354,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fn) {
|
if(breakfirst) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "alpm_list.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
@ -62,7 +64,8 @@ int _alpm_copyfile(const char *src, const char *dest);
|
|||||||
char *_alpm_strtrim(char *str);
|
char *_alpm_strtrim(char *str);
|
||||||
int _alpm_lckmk();
|
int _alpm_lckmk();
|
||||||
int _alpm_lckrm();
|
int _alpm_lckrm();
|
||||||
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
|
int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn);
|
||||||
|
int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst);
|
||||||
int _alpm_rmrf(const char *path);
|
int _alpm_rmrf(const char *path);
|
||||||
int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
|
int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
|
||||||
int _alpm_run_chroot(const char *root, const char *cmd);
|
int _alpm_run_chroot(const char *root, const char *cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user