On 9/8/25 04:28, Alyssa Ross wrote:
Demi Marie Obenour <demiobenour@gmail.com> writes:
These calls were made to work around permission problems, but it is much cleaner to solve these problems by making every directory in the new filesystem image writable so that cp can write to it.
Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com> --- scripts/make-erofs.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/scripts/make-erofs.sh b/scripts/make-erofs.sh index 3f211d848b938405510d0dbf6b11cf5512c9ef5d..e63bcbed9c3028f0f2b55431d46ba9ec67bc26ef 100755 --- a/scripts/make-erofs.sh +++ b/scripts/make-erofs.sh @@ -37,18 +37,18 @@ while read -r arg1; do fi echo
- parent="$(dirname "$arg2")" - awk -v parent="$parent" -v root="$root" 'BEGIN { - n = split(parent, components, "/") - for (i = 1; i <= n; i++) { - printf "%s/", root - for (j = 1; j <= i; j++) - printf "%s/", components[j] - print - } - }' | xargs -rd '\n' chmod +w -- 2>/dev/null || : - mkdir -p -- "$root/$parent" + if [ "$arg2" = / ]; then + cp -RT -- "$arg1" "$root" + # Nix store paths are read-only, so fix up permissions + # so that subsequent copies can write to directories + # created by the above copy. This means giving all + # directories 0755 permissions. + find "$root" -type d -exec chmod 0755 -- '{}' +
Won't this be much slower, since it runs across the whole root every time? We're going from one chmod() per path component to one for each directory in root, aren't we?
The root directory is always the first one populated. Most of the root filesystem is the Nix store, which this skips. The call to find operates on only the stuff *not* in the Nix store. Also, there are significantly fewer calls to fork() and execve(). chmod is called with many arguments at once by find.
+ continue + fi
+ parent=$(dirname "$arg2") + mkdir -p -- "$root/$parent" cp -RT -- "$arg1" "$root/$arg2" done
-- 2.51.0 -- Sincerely, Demi Marie Obenour (she/her/hers)