Skip to content

Commit 7850e7c

Browse files
jmooringclaude
authored andcommitted
commands: Skip chmod for files without owner-write permission
Closes gohugoio#14507 Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 86786c9 commit 7850e7c

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

commands/server.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,14 +1160,14 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
11601160
return err
11611161
}
11621162

1163+
// chmodFilter is a ChmodFilter for static syncing.
1164+
// Returns true to skip syncing permissions for directories and files without
1165+
// owner-write permission. The primary use case is files from the module cache (0444).
11631166
func chmodFilter(dst, src os.FileInfo) bool {
1164-
// Hugo publishes data from multiple sources, potentially
1165-
// with overlapping directory structures. We cannot sync permissions
1166-
// for directories as that would mean that we might end up with write-protected
1167-
// directories inside /public.
1168-
// One example of this would be syncing from the Go Module cache,
1169-
// which have 0555 directories.
1170-
return src.IsDir()
1167+
if src.IsDir() {
1168+
return true
1169+
}
1170+
return src.Mode().Perm()&0o200 == 0
11711171
}
11721172

11731173
func cleanErrorLog(content string) string {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
hugo
2+
3+
# Verify published files are writable.
4+
[!windows] exec sh -c 'test -w public/a.txt'
5+
[!windows] exec sh -c 'test -w public/sitemap.xml'
6+
7+
[windows] exec cmd /c attrib public\a.txt
8+
[windows] ! stdout 'R.*public'
9+
[windows] exec cmd /c attrib public\sitemap.xml
10+
[windows] ! stdout 'R.*public'
11+
12+
-- hugo.toml --
13+
baseURL = 'https://example.org/'
14+
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
15+
16+
[[module.imports]]
17+
path = 'github.com/gohugoio/hugoTestModule2'
18+
-- content/_index.md --
19+
---
20+
title: home
21+
---
22+
-- layouts/all.html --
23+
{{ .Title }}
24+
-- go.mod --
25+
module github.com/gohugoio/tests/testIssue14507
26+
27+
go 1.23

0 commit comments

Comments
 (0)