AgentD / squashfs-tools-ng

A new set of tools and libraries for working with SquashFS images
Other
194 stars 30 forks source link

`gensquashfs@1.3.1` fails to pack directory with `glob` #129

Open birunts opened 1 month ago

birunts commented 1 month ago

Having example directory structure:

└ misc
  ├── build
  │   ├── subbuild
  │   │   └── subtool.py
  │   └── test.sh
  ├── test_a.txt
  └── test_b.txt

and a packfile:

glob /a/b/c 0775 0 0 -type d -- misc
glob /a/b/c 0775 0 0 -type f -name "*" -- misc

Trying to pack misc directory content to /a/b/c fails with:

$ gensquashfs --pack-file packfile --pack-dir=$(pwd) output.squashfs
packing a/b/c/build/subbuild/subtool.py
a/b/c/build/subbuild/subtool.py: No such file or directory

The problem is with populate_dir() function which takes output name as an input file.

Looks like tree_node_t.data.file.input_file is not set. This would most probably need set extra for S_ISREG == true.

AgentD commented 1 week ago

Hi @birunts ,

yes the field input_file in tree_node_t stores the full source path, if applicable. When we scan a directory, or the pack file does not specify a source path (i.e. same path as on-disk), we can skip that and instead reconstruct the path in populate_dir() from the tree node.

The problem in your case is that we scanning a directory hierarchy under a tree node that isn't root (here a/b/c), but the scanning code fails to test for that. We then end up with broken paths when packing the files, because the path only matches up to that root node.

On current master, the problem has apparently been fixed while refactoring the scanning code.

I managed to fix your test case with the 1.3.x branch by patching the directory scanning code, to store the full path if the root node is not the root of the tree.

Here is the diff: file_prefix.diff.gz

I hope this works for you? I will try to reconcile this with the Windows port, do some more testing and get another patch level release out soon.

Thanks for reporting!