Skip to content

Commit

Permalink
pkg: allow filtering files at install time
Browse files Browse the repository at this point in the history
Add 2 new options: FILES_IGNORE_GLOB and FILES_IGNORE_REGEX which allows
a consumer to filter out some files from installation a installation
time

for example:
$ pkg -o FILES_IGNORE_REGEX=".*man.*\.gz$" \
      -o FILES_IGNORE_GLOB="*/share/doc/*" \
      install package

Will install all the files from "package" but skip documentation and
manpages
  • Loading branch information
bapt committed Aug 26, 2021
1 parent 5893555 commit 913c637
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libpkg/pkg_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@ pkg_extract_finalize(struct pkg *pkg)
install_as_user = (getenv("INSTALL_AS_USER") != NULL);

while (pkg_files(pkg, &f) == EPKG_OK) {

if (match_ucl_lists(f->path,
pkg_config_get("FILES_IGNORE_GLOB"),
pkg_config_get("FILES_IGNORE_REGEX")))
continue;
append_touched_file(f->path);
if (*f->temppath == '\0')
continue;
Expand Down Expand Up @@ -1030,6 +1035,10 @@ pkg_rollback_pkg(struct pkg *p)
struct pkg_file *f = NULL;

while (pkg_files(p, &f) == EPKG_OK) {
if (match_ucl_lists(f->path,
pkg_config_get("FILES_IGNORE_GLOB"),
pkg_config_get("FILES_IGNORE_REGEX")))
continue;
if (*f->temppath != '\0') {
unlinkat(p->rootfd, f->temppath, 0);
}
Expand Down Expand Up @@ -1128,6 +1137,11 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
/* analyse previous files */
f = NULL;
while (pkg_files(pkg, &f) == EPKG_OK) {
if (match_ucl_lists(f->path,
pkg_config_get("FILES_IGNORE_GLOB"),
pkg_config_get("FILES_IGNORE_REGEX"))) {
continue;
}
if (faccessat(pkg->rootfd, RELATIVE_PATH(f->path), F_OK, 0) == 0) {
f->previous = PKG_FILE_EXIST;
if (!pkgdb_file_exists(db, f->path)) {
Expand Down Expand Up @@ -1373,6 +1387,10 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)

hardlinks = kh_init_hls();
while (pkg_files(pkg, &f) == EPKG_OK) {
if (match_ucl_lists(f->path,
pkg_config_get("FILES_IGNORE_GLOB"),
pkg_config_get("FILES_IGNORE_REGEX")))
continue;
if (fstatat(fromfd, RELATIVE_PATH(f->path), &st,
AT_SYMLINK_NOFOLLOW) == -1) {
kh_destroy_hls(hardlinks);
Expand Down
12 changes: 12 additions & 0 deletions libpkg/pkg_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,18 @@ static struct config_entry c[] = {
"FALSE",
"Accept legacy package extensions when creating the repository",
},
{
PKG_ARRAY,
"FILES_IGNORE_GLOB",
"NULL",
"patterns of files to not extract from the package",
},
{
PKG_ARRAY,
"FILES_IGNORE_REGEX",
"NULL",
"patterns of files to not extract from the package",
},
};

static bool parsed = false;
Expand Down
6 changes: 6 additions & 0 deletions libpkg/pkgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,12 @@ pkgdb_register_pkg(struct pkgdb *db, struct pkg *pkg, int forced,

while (pkg_files(pkg, &file) == EPKG_OK) {
bool permissive = false;
if (match_ucl_lists(file->path,
pkg_config_get("FILES_IGNORE_GLOB"),
pkg_config_get("FILES_IGNORE_REGEX"))) {
continue;
printf("matched\n");
}

ret = run_prstmt(FILES, file->path, file->sum, package_id);
if (ret == SQLITE_DONE)
Expand Down

0 comments on commit 913c637

Please sign in to comment.