From 43b34b05d0b8663d041a256c3b51cb41d7a76305 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 17 Feb 2023 16:17:53 +0100 Subject: [PATCH] entrypoint: chown /data recursively to handle subdirs pre-created as root to mount volumes. --- entrypoint/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/entrypoint/main.go b/entrypoint/main.go index 9885ed6..a63e6f3 100644 --- a/entrypoint/main.go +++ b/entrypoint/main.go @@ -8,6 +8,7 @@ import ( "encoding/json" "fmt" "github.com/go-ini/ini" + "io/fs" "io/ioutil" "os" "os/exec" @@ -43,7 +44,14 @@ func entrypoint() error { if os.Getuid() == 0 { logf("info", "Giving %s to the www-data user as we're root", dataVolume) - if err := os.Chown(dataVolume, wwwdataUid, wwwdataUid); err != nil { + err := filepath.WalkDir(dataVolume, func(path string, _ fs.DirEntry, err error) error { + if err != nil { + return err + } + + return os.Lchown(path, wwwdataUid, wwwdataUid) + }) + if err != nil { return err }