diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-10-20 11:25:16 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-10-20 13:04:58 +0200 |
commit | 352be5ba8702017997587b3b99c42e66857b0627 (patch) | |
tree | cdb44bb7166606f3587627dfb989d0cd2fe8d83a /commands | |
parent | d37606d2c2174e20cfba5150812da83378078f09 (diff) | |
download | hugo-352be5ba8702017997587b3b99c42e66857b0627.tar.gz hugo-352be5ba8702017997587b3b99c42e66857b0627.zip |
Make sure that HugoSites is always closed when done
Including all the integration tests.
Diffstat (limited to 'commands')
-rw-r--r-- | commands/commandeer.go | 19 | ||||
-rw-r--r-- | commands/server.go | 4 |
2 files changed, 19 insertions, 4 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 06565d45d..ad2adf3a2 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -42,6 +42,7 @@ import ( "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/paths" + "github.com/gohugoio/hugo/common/types" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config/allconfig" "github.com/gohugoio/hugo/deps" @@ -66,6 +67,12 @@ func Execute(args []string) error { } args = mapLegacyArgs(args) cd, err := x.Execute(context.Background(), args) + if cd != nil { + if closer, ok := cd.Root.Command.(types.Closer); ok { + closer.Close() + } + } + if err != nil { if err == errHelp { cd.CobraCommand.Help() @@ -149,6 +156,18 @@ func (r *rootCommand) isVerbose() bool { return r.logger.Level() <= logg.LevelInfo } +func (r *rootCommand) Close() error { + if r.hugoSites != nil { + r.hugoSites.DeleteFunc(func(key configKey, value *hugolib.HugoSites) bool { + if value != nil { + value.Close() + } + return false + }) + } + return nil +} + func (r *rootCommand) Build(cd *simplecobra.Commandeer, bcfg hugolib.BuildCfg, cfg config.Provider) (*hugolib.HugoSites, error) { h, err := r.Hugo(cfg) if err != nil { diff --git a/commands/server.go b/commands/server.go index b16bf3148..84d4165f0 100644 --- a/commands/server.go +++ b/commands/server.go @@ -1012,10 +1012,6 @@ func (c *serverCommand) serve() error { c.r.Println("Error:", err) } - if h := c.hugoTry(); h != nil { - h.Close() - } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() wg2, ctx := errgroup.WithContext(ctx) |