Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: skip unreadable directories instead of discarding the project file tree (#3393)
Kyle Mendell7ada13ff5509
diff --git a/backend/pkg/projects/project_files.go b/backend/pkg/projects/project_files.goindex c43bfe8d3..7d172823d 100644--- a/backend/pkg/projects/project_files.go+++ b/backend/pkg/projects/project_files.go@@ -6,6 +6,7 @@ import ("hash""io""io/fs"+ "log/slog""os""path""path/filepath"@@ -106,6 +107,16 @@ type projectFileTreeWalkerInternal struct {func (w *projectFileTreeWalkerInternal) visit(rel string, entry fs.DirEntry, walkErr error) error {if walkErr != nil {+ // fs.WalkDir reports a directory it could not read by invoking the+ // callback a second time with the ReadDir error. Skipping keeps the+ // rest of the tree intact instead of discarding every sibling; the+ // directory itself was already recorded by the first call. A failure+ // on the project root, or one that is not a permission/disappearance+ // error, stays fatal so real I/O problems remain observable.+ if rel != "." && entry != nil && entry.IsDir() && (os.IsPermission(walkErr) || os.IsNotExist(walkErr)) {+ slog.Debug("Skipping unreadable project subdirectory", "relativePath", rel, "error", walkErr)+ return fs.SkipDir+ }return walkErr}if rel == "." {@@ -137,7 +148,18 @@ func (w *projectFileTreeWalkerInternal) visit(rel string, entry fs.DirEntry, walinfo, err := entry.Info()if err != nil {- return errors.WrapIf(err, "inspect project file")+ // An entry that vanished mid-walk or that we are not allowed to stat is+ // skipped rather than failing the whole tree; anything else surfaces.+ // fs.SkipDir on a non-directory would break out of the parent's sibling+ // loop, so split on IsDir.+ if !os.IsPermission(err) && !os.IsNotExist(err) {+ return err+ }+ slog.Debug("Skipping unreadable project entry", "relativePath", rel, "error", err)+ if entry.IsDir() {+ return fs.SkipDir+ }+ return nil}// fs.WalkDir visits entries in deterministic lexical order, so hashingdiff --git a/backend/pkg/projects/project_files_unix_test.go b/backend/pkg/projects/project_files_unix_test.gonew file mode 100644index 000000000..50eebf7db--- /dev/null+++ b/backend/pkg/projects/project_files_unix_test.go@@ -0,0 +1,59 @@+//go:build unix++package projects++import (+ "os"+ "path/filepath"+ "testing"++ "github.com/stretchr/testify/assert"+ "github.com/stretchr/testify/require"+)++// Reproduces issue #3309: a project directory containing a bind-mount data+// folder Arcane cannot read must still list everything else. Before the fix a+// single EACCES from fs.WalkDir aborted the walk, so the whole tree (and the+// revision that gates file edits) came back empty.+func TestReadProjectFileTree_SkipsUnreadableDirectory(t *testing.T) {+ if os.Geteuid() == 0 {+ t.Skip("permission bits are ignored when running as root")+ }++ projectDir := t.TempDir()+ require.NoError(t, os.WriteFile(filepath.Join(projectDir, "compose.yaml"), []byte("include: []\n"), 0o644))+ require.NoError(t, os.MkdirAll(filepath.Join(projectDir, "includes"), 0o755))+ require.NoError(t, os.WriteFile(filepath.Join(projectDir, "includes", "networks.yaml"), []byte("networks: {}\n"), 0o644))++ workdir := filepath.Join(projectDir, "volumes", "adguard-home", "workdir")+ require.NoError(t, os.MkdirAll(workdir, 0o755))+ require.NoError(t, os.WriteFile(filepath.Join(workdir, "data.db"), []byte("opaque"), 0o644))+ require.NoError(t, os.Chmod(workdir, 0o000))+ // Restore before t.TempDir's own cleanup runs, or it cannot remove the tree.+ t.Cleanup(func() { _ = os.Chmod(workdir, 0o755) })++ files, revision, _, err := ReadProjectFileTree(projectDir, 5, "", "compose.yaml", 0)+ require.NoError(t, err)+ require.NotEmpty(t, revision, "an empty revision blocks every project file edit")++ relativePaths := make([]string, 0, len(files))+ for _, file := range files {+ relativePaths = append(relativePaths, file.RelativePath)+ }++ // Siblings of the unreadable directory survive, and the directory itself is+ // still listed - just without children.+ assert.ElementsMatch(t, []string{+ "includes",+ "includes/networks.yaml",+ "volumes",+ "volumes/adguard-home",+ "volumes/adguard-home/workdir",+ }, relativePaths)++ // The compare walk in ApplyProjectFileChanges skips identically, so the+ // optimistic-concurrency check does not spuriously conflict.+ _, again, _, err := ReadProjectFileTree(projectDir, 5, "", "compose.yaml", 0)+ require.NoError(t, err)+ assert.Equal(t, revision, again)+}