18
lib/conf.c
18
lib/conf.c
@@ -145,6 +145,19 @@ store_ignored_pkg(struct xbps_handle *xhp, const char *pkgname)
|
||||
xbps_dbg_printf(xhp, "Added ignored package: %s\n", pkgname);
|
||||
}
|
||||
|
||||
static void
|
||||
store_noextract(struct xbps_handle *xhp, const char *value)
|
||||
{
|
||||
if (*value == '\0')
|
||||
return;
|
||||
if (xhp->noextract == NULL) {
|
||||
xhp->noextract = xbps_array_create();
|
||||
assert(xhp->noextract);
|
||||
}
|
||||
xbps_array_add_cstring(xhp->noextract, value);
|
||||
xbps_dbg_printf(xhp, "Added noextract pattern: %s\n", value);
|
||||
}
|
||||
|
||||
enum {
|
||||
KEY_ERROR = 0,
|
||||
KEY_ARCHITECTURE,
|
||||
@@ -152,6 +165,7 @@ enum {
|
||||
KEY_CACHEDIR,
|
||||
KEY_IGNOREPKG,
|
||||
KEY_INCLUDE,
|
||||
KEY_NOEXTRACT,
|
||||
KEY_PRESERVE,
|
||||
KEY_REPOSITORY,
|
||||
KEY_ROOTDIR,
|
||||
@@ -169,6 +183,7 @@ static const struct key {
|
||||
{ "cachedir", 8, KEY_CACHEDIR },
|
||||
{ "ignorepkg", 9, KEY_IGNOREPKG },
|
||||
{ "include", 7, KEY_INCLUDE },
|
||||
{ "noextract", 9, KEY_NOEXTRACT },
|
||||
{ "preserve", 8, KEY_PRESERVE },
|
||||
{ "repository", 10, KEY_REPOSITORY },
|
||||
{ "rootdir", 7, KEY_ROOTDIR },
|
||||
@@ -353,6 +368,9 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested)
|
||||
case KEY_IGNOREPKG:
|
||||
store_ignored_pkg(xhp, val);
|
||||
break;
|
||||
case KEY_NOEXTRACT:
|
||||
store_noextract(xhp, val);
|
||||
break;
|
||||
case KEY_INCLUDE:
|
||||
/* Avoid double-nested parsing, only allow it once */
|
||||
if (nested) {
|
||||
|
@@ -305,6 +305,15 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
xucd_stats = true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Skip files that match noextract patterns from configuration file.
|
||||
*/
|
||||
if (xhp->noextract && xbps_patterns_match(xhp->noextract, entry_pname+1)) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FILE_PRESERVED, 0,
|
||||
pkgver, "%s: file `%s' won't be extracted, "
|
||||
"it matches a noextract pattern.", pkgver, entry_pname);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* Always check that extracted file exists and hash
|
||||
* doesn't match, in that case overwrite the file.
|
||||
@@ -323,7 +332,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
"and must be preserved, skipping.\n", entry_pname);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FILE_PRESERVED, 0,
|
||||
pkgver, "%s: file `%s' won't be extracted, "
|
||||
"it's preserved.\n", pkgver, entry_pname);
|
||||
"it's preserved.", pkgver, entry_pname);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
24
lib/util.c
24
lib/util.c
@@ -648,3 +648,27 @@ xbps_symlink_target(struct xbps_handle *xhp, const char *path, const char *tgt)
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool
|
||||
xbps_patterns_match(xbps_array_t patterns, const char *path)
|
||||
{
|
||||
bool match = false;
|
||||
|
||||
if (patterns == NULL)
|
||||
return false;
|
||||
|
||||
for (unsigned int i = 0; i < xbps_array_count(patterns); i++) {
|
||||
const char *pattern = NULL;
|
||||
bool negate = false;
|
||||
if (!xbps_array_get_cstring_nocopy(patterns, i, &pattern))
|
||||
continue;
|
||||
if (pattern == NULL)
|
||||
continue;
|
||||
if ((negate = *pattern == '!') || *pattern == '\\')
|
||||
pattern++;
|
||||
if (fnmatch(pattern, path, 0) == 0)
|
||||
match = !negate;
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
Reference in New Issue
Block a user