diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 13cc942fc..74f59b03c 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -426,16 +426,10 @@ func (d *SourceFilesystem) RealFilename(rel string) string { } // Contains returns whether the given filename is a member of the current filesystem. +// It's stat-free, so it also works for deleted files. func (d *SourceFilesystem) Contains(filename string) bool { - for _, dir := range d.mounts() { - if !dir.IsDir() { - continue - } - if strings.HasPrefix(filename, dir.Meta().Filename) { - return true - } - } - return false + cps, _ := d.ReverseLookup(filename, false) + return len(cps) > 0 } // RealDirs gets a list of absolute paths to directories starting from the given diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index 823f9811e..0feaada59 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -1080,6 +1080,8 @@ func (h *HugoSites) processPartialFileEvents(ctx context.Context, l logg.LevelLo changes = append(changes, identity.GenghisKhan) case files.ComponentFolderArchetypes: // Ignore for now. + case files.ComponentFolderStatic: + // Handled by the static file syncer. default: panic(fmt.Sprintf("unknown component: %q", pathInfo.Component())) } diff --git a/testscripts/server/server__delete_static_file_mount.txt b/testscripts/server/server__delete_static_file_mount.txt new file mode 100644 index 000000000..df77b2a04 --- /dev/null +++ b/testscripts/server/server__delete_static_file_mount.txt @@ -0,0 +1,32 @@ +# Test the hugo server command when removing a file mounted into static. +# See issue 15174. + +hugo server & + +waitServer + +rm myfiles/robots.txt + +sleep 2 + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +[[module.mounts]] +source = "content" +target = "content" +[[module.mounts]] +source = "layouts" +target = "layouts" +[[module.mounts]] +source = "myfiles/robots.txt" +target = "static/robots.txt" +-- layouts/all.html -- +All. +-- content/p1.md -- +-- myfiles/robots.txt -- +robots diff --git a/testscripts/server/server__delete_static_mount_dir.txt b/testscripts/server/server__delete_static_mount_dir.txt new file mode 100644 index 000000000..8c338812e --- /dev/null +++ b/testscripts/server/server__delete_static_mount_dir.txt @@ -0,0 +1,32 @@ +# Test the hugo server command when removing a directory mounted into static. +# See issue 15174. + +hugo server & + +waitServer + +rm mystatic/foo + +sleep 2 + +stopServer +! stderr . + +-- hugo.toml -- +title = "Hugo Server Test" +baseURL = "https://example.org/" +disableKinds = ["taxonomy", "term", "sitemap"] +[[module.mounts]] +source = "content" +target = "content" +[[module.mounts]] +source = "layouts" +target = "layouts" +[[module.mounts]] +source = "mystatic/foo" +target = "static/foo" +-- layouts/all.html -- +All. +-- content/p1.md -- +-- mystatic/foo/static.txt -- +static