[pacman-dev] [PATCH 1/2] Add alpm_option_match_noextract
This is useful for frontends testing whether a file is in NoExtract Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/alpm.h | 1 + lib/libalpm/handle.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 1831fcf..234bd6b 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -827,6 +827,7 @@ alpm_list_t *alpm_option_get_noextracts(alpm_handle_t *handle); int alpm_option_add_noextract(alpm_handle_t *handle, const char *path); int alpm_option_set_noextracts(alpm_handle_t *handle, alpm_list_t *noextract); int alpm_option_remove_noextract(alpm_handle_t *handle, const char *path); +int alpm_option_match_noextract(alpm_handle_t *handle, const char *path); /** @} */ /** @name Accessors to the list of ignored packages. diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 6545592..5ef619e 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -542,6 +542,11 @@ int SYMEXPORT alpm_option_remove_noextract(alpm_handle_t *handle, const char *pa return _alpm_option_strlist_rem(handle, &(handle->noextract), path); } +int SYMEXPORT alpm_option_match_noextract(alpm_handle_t *handle, const char *path) +{ + return _alpm_fnmatch_patterns(handle->noextract, path); +} + int SYMEXPORT alpm_option_add_ignorepkg(alpm_handle_t *handle, const char *pkg) { return _alpm_option_strlist_add(handle, &(handle->ignorepkg), pkg); -- 2.1.3
When checking a packages files, ignore any missing files in NoExtract Signed-off-by: Allan McRae <allan@archlinux.org> --- src/pacman/check.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/pacman/check.c b/src/pacman/check.c index 7109c7a..628e79d 100644 --- a/src/pacman/check.c +++ b/src/pacman/check.c @@ -26,18 +26,23 @@ #include "conf.h" #include "util.h" -static int check_file_exists(const char *pkgname, char *filepath, +static int check_file_exists(const char *pkgname, char *filepath, size_t rootlen, struct stat *st) { /* use lstat to prevent errors from symlinks */ if(llstat(filepath, st) != 0) { - if(config->quiet) { - printf("%s %s\n", pkgname, filepath); + if(alpm_option_match_noextract(config->handle, filepath + rootlen) == 0) { + /* NoExtract */ + return -1; } else { - pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n", - pkgname, filepath, strerror(errno)); + if(config->quiet) { + printf("%s %s\n", pkgname, filepath); + } else { + pm_printf(ALPM_LOG_WARNING, "%s: %s (%s)\n", + pkgname, filepath, strerror(errno)); + } + return 1; } - return 1; } return 0; @@ -209,6 +214,7 @@ int check_pkg_fast(alpm_pkg_t *pkg) for(i = 0; i < filelist->count; i++) { const alpm_file_t *file = filelist->files + i; struct stat st; + int exists; const char *path = file->name; size_t plen = strlen(path); @@ -218,7 +224,8 @@ int check_pkg_fast(alpm_pkg_t *pkg) } strcpy(filepath + rootlen, path); - if(check_file_exists(pkgname, filepath, &st) == 0) { + exists = check_file_exists(pkgname, filepath, rootlen, &st); + if(exists == 0) { int expect_dir = path[plen - 1] == '/' ? 1 : 0; int is_dir = S_ISDIR(st.st_mode) ? 1 : 0; if(expect_dir != is_dir) { @@ -226,7 +233,7 @@ int check_pkg_fast(alpm_pkg_t *pkg) pkgname, filepath); ++errors; } - } else { + } else if(exists == 1) { ++errors; } } @@ -278,6 +285,7 @@ int check_pkg_full(alpm_pkg_t *pkg) mode_t type; size_t file_errors = 0; int backup = 0; + int exists; /* strip leading "./" from path entries */ if(path[0] == '.' && path[1] == '/') { @@ -310,9 +318,13 @@ int check_pkg_full(alpm_pkg_t *pkg) } strcpy(filepath + rootlen, path); - if(check_file_exists(pkgname, filepath, &st) == 1) { + exists = check_file_exists(pkgname, filepath, rootlen, &st); + if(exists == 1) { errors++; continue; + } else if(exists == -1) { + /* NoExtract */ + continue; } type = archive_entry_filetype(entry); -- 2.1.3
participants (1)
-
Allan McRae