mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-12 20:13:59 +02:00
Work around --gc failure on Windows <= 10
This applies two related fixes/improvements: * The --gc now keeps empty `_resources/_gen/images` etc folders, even if empty. This should have been the behaviour from the start. * Also, if removal of an empty dir on Windows fails with the "used by another process" error, just ignore it for now. Fixes #10781
This commit is contained in:
22
cache/filecache/filecache_pruner.go
vendored
22
cache/filecache/filecache_pruner.go
vendored
@@ -17,6 +17,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
@@ -66,6 +68,7 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
|
||||
if info.IsDir() {
|
||||
f, err := c.Fs.Open(name)
|
||||
|
||||
if err != nil {
|
||||
// This cache dir may not exist.
|
||||
return nil
|
||||
@@ -74,7 +77,24 @@ func (c *Cache) Prune(force bool) (int, error) {
|
||||
_, err = f.Readdirnames(1)
|
||||
if err == io.EOF {
|
||||
// Empty dir.
|
||||
err = c.Fs.Remove(name)
|
||||
if name == "." {
|
||||
// e.g. /_gen/images -- keep it even if empty.
|
||||
err = nil
|
||||
} else {
|
||||
err = c.Fs.Remove(name)
|
||||
if err != nil {
|
||||
if runtime.GOOS == "windows" {
|
||||
if strings.Contains(err.Error(), "used by another process") {
|
||||
// See https://github.com/gohugoio/hugo/issues/10781
|
||||
// This is a known issue on Windows with Go 1.20.
|
||||
// There's not much we can do about it.
|
||||
// So just return nil.
|
||||
err = nil
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil && !herrors.IsNotExist(err) {
|
||||
|
Reference in New Issue
Block a user