]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
commands: Skip chmod for files without owner-write permission
authorJoe Mooring <joe.mooring@veriphor.com>
Fri, 13 Feb 2026 01:42:27 +0000 (17:42 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 13 Feb 2026 17:23:56 +0000 (18:23 +0100)
Closes #14507

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
commands/server.go
testscripts/commands/hugo__static_issue14507.txt [new file with mode: 0644]

index a9454ffc29034f81b42a57c3192744602eb063a1..25c16bc4d49968fb5a959caa297c075fbf85d0e2 100644 (file)
@@ -1160,14 +1160,14 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
        return err
 }
 
+// chmodFilter is a ChmodFilter for static syncing.
+// Returns true to skip syncing permissions for directories and files without
+// owner-write permission. The primary use case is files from the module cache (0444).
 func chmodFilter(dst, src os.FileInfo) bool {
-       // Hugo publishes data from multiple sources, potentially
-       // with overlapping directory structures. We cannot sync permissions
-       // for directories as that would mean that we might end up with write-protected
-       // directories inside /public.
-       // One example of this would be syncing from the Go Module cache,
-       // which have 0555 directories.
-       return src.IsDir()
+       if src.IsDir() {
+               return true
+       }
+       return src.Mode().Perm()&0o200 == 0
 }
 
 func cleanErrorLog(content string) string {
diff --git a/testscripts/commands/hugo__static_issue14507.txt b/testscripts/commands/hugo__static_issue14507.txt
new file mode 100644 (file)
index 0000000..429b9b9
--- /dev/null
@@ -0,0 +1,27 @@
+hugo
+
+# Verify published files are writable.
+[!windows] exec sh -c 'test -w public/a.txt'
+[!windows] exec sh -c 'test -w public/sitemap.xml'
+
+[windows] exec cmd /c attrib public\a.txt
+[windows] ! stdout 'R.*public'
+[windows] exec cmd /c attrib public\sitemap.xml
+[windows] ! stdout 'R.*public'
+
+-- hugo.toml --
+baseURL = 'https://example.org/'
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+
+[[module.imports]]
+path = 'github.com/gohugoio/hugoTestModule2'
+-- content/_index.md --
+---
+title: home
+---
+-- layouts/all.html --
+{{ .Title }}
+-- go.mod --
+module github.com/gohugoio/tests/testIssue14507
+
+go 1.23