4

I am having issues excluding a specific file from a squashfs. I want to be able to exclude all file types ending with *.db but have had no luck.

Whenever I run the mksquashfs command with the arguments to exclude the file, it always includes the file. I have tried many different variants of the command. My test script is below:

#!/bin/bash

OPT="-regex -e '*.db' "

echo -e "Creating squashfs..."
mksquashfs test test.package ${OPT}
echo "Ran the following command: mksquashfs pf test.package ${OPT}"

echo -e "Uncompressing squashfs..."
mkdir pf_post
unsquashfs -f -d test_post/ test.package 

echo
read -p "press any key to continue..."

rm test.package
rm -r test_post

The tree of the test directory is below. Both instances of test.db should be excluded but it does not seem to work.

test
├── test
│   └── test.db
├── test.ab
├── test.cd
├── test.db
├── test.ef
├── test.gh
└── test.sh

Switching it to wildcard partially fixed it. That excluded the first .db file, but the second one a sub-directory deeper was not excluded. Is there a way to tell it to exclude all '.db' files and not just the first in the lowest directory? Below is the code that excluded the first file type. Both solutions still did not exclude the subdirectory '.db' files.

mksquashfs test test.package -wildcards -e '*.db'

mksquashfs test test.package -regex -e '\.db$'

Some of the above solutions were provided from the following link, but I hit a dead end where I was unable to exclude all of the '.db' files. https://askubuntu.com/questions/628585/mksquashfs-not-excluding-file

1 Answer 1

8

This information is contained in the Squashfs RELEASE-README

In addition to wildcards/regex expressions, exclude files can be "anchored" or "non-anchored". An anchored exclude is one which matches from the root of the directory and nowhere else, a non-anchored exclude matches anywhere. For example given the directory hierarchy "a/b/c/a/b", the anchored exclude "a/b" will match "a/b" at the root of the directory hierarchy, but it will not match the "/a/b" sub-directory within directory "c", whereas a non-anchored exclude would.

Non-anchored excludes

By default excludes match from the top level directory, but it is often useful to exclude a file matching anywhere in the source directories. For this non-anchored excludes can be used, specified by prefixing the exclude pattern with "... " (i.e., three dots followed by a space, and then the pattern).

Examples:

  1. mksquashfs example image.sqsh -wildcards -e '... *.gz'

    Exclude files matching "*.gz" anywhere in the source directories. For example this will match "example.gz", "test/example.gz", and "test/test/example.gz".

  2. mksquashfs example image.sqsh -wildcards -e '... [Tt]est/*.gz'

    Exclude files matching "*.gz" inside directories called "Test" or "test" that occur anywhere in the source directories.

Again, using extended wildcards, negative matching is also possible.

  1. mksquashfs example image.sqsh -wildcards -e '... !(*data*).gz'

    Exclude all files matching "*.gz" anywhere in the source directories, except those with "data" in the name.

2
  • Looks like that three dots and a space was what I needed! That fixed the problem! Thanks!
    – tardis89
    Commented Aug 8, 2017 at 13:08
  • 1
    mksquashfs test test.package -wildcards -e '... *.db' was what it took to fix it.
    – tardis89
    Commented Aug 8, 2017 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.