Repository: gohugoio/hugo (language: go)

Issue:
panic: Readdirnames with positive n not implemented
Latest hugo:

```
❯ hugo version
hugo v0.97.0-c07f3626e7c8160943591f4d209977efa02c3dca+extended linux/amd64 BuildDate=2022-04-14T08:45:07Z VendorInfo=gohugoio
```

System is Ubuntu 21.10.

Adding the new `--renderStaticToFile` results in a panic.

The error is thrown here:

https://github.com/bep/overlayfs/blame/f2827b4630ef27b64116cde8133733d6a82d91ca/overlayfs.go#L222

The comment above the code says "Note that only positive n is implemented." But the line in question checks if n is larger than 0 and the error says "

```
panic: Readdirnames with positive n not implemented

goroutine 1 [running]:
github.com/bep/overlayfs.(*Dir).Readdirnames(0x96c96a?, 0x27c4ec0?)
        /go/pkg/mod/github.com/bep/overlayfs@v0.4.0/overlayfs.go:229 +0x11e
github.com/gohugoio/hugo/cache/filecache.(*Cache).Prune.func1({0x0?, 0xc000954360?}, {0x7fb8948f3d28, 0xc00e901308}, {0xc000954360?, 0xc001e697b0?})
        /root/project/hugo/cache/filecache/filecache_pruner.go:73 +0x270
github.com/spf13/afero.walk({0x27c58c0, 0xc000941340}, {0x0, 0x0}, {0x7fb8948f3d28, 0xc00e901308}, 0xc001e69870)
        /go/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:44 +0x78
github.com/spf13/afero.Walk({0x27c58c0, 0xc000941340}, {0x0, 0x0}, 0xc001e69870)
        /go/pkg/mod/github.com/spf13/afero@v1.8.2/path.go:105 +0x88
github.com/gohugoio/hugo/cache/filecache.(*Cache).Prune(0x0?, 0x0?)
        /root/project/hugo/cache/filecache/filecache_pruner.go:59 +0x85
github.com/gohugoio/hugo/cache/filecache.Caches.Prune(0x1fdbe80?)
        /root/project/hugo/cache/filecache/filecache_pruner.go:34 +0xae
github.com/gohugoio/hugo/hugolib.(*HugoSites).GC(...)
        /root/project/hugo/hugolib/prune_resources.go:18
github.com/gohugoio/hugo/commands.(*commandeer).fullBuild(0xc00081e400, 0x0)
        /root/project/hugo/commands/hugo.go:337 +0x45e
github.com/gohugoio/hugo/commands.(*commandeer).serverBuild(0xc00081e400)
        /root/project/hugo/commands/hugo.go:560 +0x7b
github.com/gohugoio/hugo/commands.(*serverCmd).server.func2(0xc00081e400, 0x224e0db?)
        /root/project/hugo/commands/server.go:261 +0xb2
github.com/gohugoio/hugo/commands.(*serverCmd).server(0xc0007da100, 0xc000431b80, {0xc000228500?, 0x9a0e60?, 0xc0007c7d00?})
        /root/project/hugo/commands/server.go:266 +0x1eb
github.com/gohugoio/hugo/commands.(*commandsBuilder).newServerCmdSignaled.func1(0xc000431b80?, {0xc00081c480?, 0x21?, 0x24?})
        /root/project/hugo/commands/server.go:95 +0x36
github.com/spf13/cobra.(*Command).execute(0xc000431b80, {0xc00081c240, 0x21, 0x24})
        /go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000802a00)
        /go/pkg/mod/github.com/spf13/cobra@v1.4.0/command.go:974 +0x3b4
github.com/gohugoio/hugo/commands.Execute({0xc00003c250, 0x22, 0x23})
        /root/project/hugo/commands/hugo.go:93 +0xb4
main.main()
        /root/project/hugo/main.go:23 +0x57
ERROR: "serve:hugo" exited with 2.
ERROR: "serve" exited with 1.
```

The command executed is 

```
# starting hugo server
hugo server \
  --gc \
  --environment development \
  --disableFastRender \
  --printUnusedTemplates \
  --printI18nWarnings \
  --navigateToChanged \
  --templateMetrics \
  --templateMetricsHints \
  --printPathWarnings \
  --poll 1s \
  --minify \
  --cleanDestinationDir \
  --renderStaticToDisk \
  --buildFuture \
  --buildDrafts \
  --buildExpired \
  --watch \
  --enableGitInfo \
  --forceSyncStatic \
  --log true --logFile hugo.log \
  --verbose \
  --verboseLog \
  --port "${PORT}" \
  --baseURL http://"${IP}"/ \
  --bind "${IP}"
```

Running only `hugo server` works fine. Modules are used, and no symlinks are used. 


Discussion / hints:
Unable to reproduce. Please provide a minimal reproducible example. 
So, this is a bug, but ... 

```bash
hugo server \
  --gc \
  --environment development \
  --disableFastRender \
  --printUnusedTemplates \
  --printI18nWarnings \
  --navigateToChanged \
  --templateMetrics \
  --templateMetricsHints \
  --printPathWarnings \
  --poll 1s \
  --minify \
  --cleanDestinationDir \
  --renderStaticToDisk \
  --buildFuture \
  --buildDrafts \
  --buildExpired \
  --watch \
  --enableGitInfo \
  --forceSyncStatic \
  --log true --logFile hugo.log \
  --verbose \
  --verboseLog \
  --port "${PORT}" \
  --baseURL http://"${IP}"/ \
  --bind "${IP}"
```

That is ... all the flags?

Running `hugo server` with `--gc` in combo with `--renderStaticToDisk` probably what breaks this, but  does not make much sense to me.



Fix patch:
diff --git a/go.mod b/go.mod
index 4465d5b4284..397be1fadd2 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
 	github.com/bep/godartsass v0.14.0
 	github.com/bep/golibsass v1.0.0
 	github.com/bep/gowebp v0.1.0
-	github.com/bep/overlayfs v0.4.0
+	github.com/bep/overlayfs v0.5.0
 	github.com/bep/tmc v0.5.1
 	github.com/clbanning/mxj/v2 v2.5.5
 	github.com/cli/safeexec v1.0.0
diff --git a/go.sum b/go.sum
index f990615dd46..71eec8a9a36 100644
--- a/go.sum
+++ b/go.sum
@@ -234,6 +234,8 @@ github.com/bep/gowebp v0.1.0 h1:4/iQpfnxHyXs3x/aTxMMdOpLEQQhFmF6G7EieWPTQyo=
 github.com/bep/gowebp v0.1.0/go.mod h1:ZhFodwdiFp8ehGJpF4LdPl6unxZm9lLFjxD3z2h2AgI=
 github.com/bep/overlayfs v0.4.0 h1:J/G5YltfU2BxO2KV/VcFzJo94jpRMjtthRNEZ+7V7uA=
 github.com/bep/overlayfs v0.4.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
+github.com/bep/overlayfs v0.5.0 h1:5F7xbjVhPSMv/PX5KYeCeEMR/17Fm20G2A0Phe+dUmc=
+github.com/bep/overlayfs v0.5.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
 github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
 github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
 github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=


Test patch: