Fix root-owned parent dirs left behind by nested volume mounts
When a named volume is mounted at a nested path like /home/developer/.local/state/opencode, Docker creates the parent directory (.local/state) as root:root. The existing chown loop only fixed the leaf mount points, leaving parents unwritable by the developer user. Add a non-recursive pre-pass that fixes ownership of the common parent dirs (.local, .local/share, .local/state, .config) so that anything creating new subdirs beneath them works correctly after a fresh container recreate. Regression introduced by commit967ce7d(devbox-state volume) and only partially addressed bya06dc5f.
This commit is contained in:
@@ -51,6 +51,22 @@ fi
|
||||
# developer user can write to them.
|
||||
FINAL_UID="${TARGET_UID:-$CURRENT_UID}"
|
||||
FINAL_GID="${TARGET_GID:-$CURRENT_GID}"
|
||||
|
||||
# First, fix parent dirs that Docker auto-creates as root:root when it
|
||||
# materializes nested mount points (e.g. mounting a volume at
|
||||
# .local/state/opencode creates .local/state as root). Non-recursive —
|
||||
# we only need the dir node itself; children are handled below or were
|
||||
# created by the user.
|
||||
for parent in \
|
||||
/home/"$USER_NAME"/.local \
|
||||
/home/"$USER_NAME"/.local/share \
|
||||
/home/"$USER_NAME"/.local/state \
|
||||
/home/"$USER_NAME"/.config; do
|
||||
if [ -d "$parent" ] && [ "$(stat -c '%u' "$parent" 2>/dev/null)" != "$FINAL_UID" ]; then
|
||||
chown "$FINAL_UID":"$FINAL_GID" "$parent" 2>/dev/null || true
|
||||
fi
|
||||
done
|
||||
|
||||
for dir in \
|
||||
/home/"$USER_NAME"/.local/share/opencode \
|
||||
/home/"$USER_NAME"/.local/state/opencode \
|
||||
|
||||
Reference in New Issue
Block a user