aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-02-09 13:52:36 +0200
committerBjørn Erik Pedersen <[email protected]>2024-02-16 13:17:53 +0100
commit639073e4fee8fd4235c1002b076e110fad4c82f2 (patch)
tree55f4c392bc4f156f8605993d3d416bd5b105cc40 /resources
parent21d9057dbfe64f668d5fc6a7f458e0984fbf7e56 (diff)
downloadhugo-639073e4fee8fd4235c1002b076e110fad4c82f2.tar.gz
hugo-639073e4fee8fd4235c1002b076e110fad4c82f2.zip
Fix rebuild with resources.Concat
Fixes #12017
Diffstat (limited to 'resources')
-rw-r--r--resources/resource.go2
-rw-r--r--resources/resource_cache.go2
-rw-r--r--resources/resource_factories/bundler/bundler.go29
-rw-r--r--resources/resource_factories/create/create.go18
4 files changed, 34 insertions, 17 deletions
diff --git a/resources/resource.go b/resources/resource.go
index 900b05a5f..73a0ad56e 100644
--- a/resources/resource.go
+++ b/resources/resource.go
@@ -171,7 +171,7 @@ func (fd *ResourceSourceDescriptor) init(r *Spec) error {
fd.MediaType = mediaType
if fd.DependencyManager == nil {
- fd.DependencyManager = identity.NopManager
+ fd.DependencyManager = r.Cfg.NewIdentityManager("resource")
}
return nil
diff --git a/resources/resource_cache.go b/resources/resource_cache.go
index a76a51b1c..bf930c71d 100644
--- a/resources/resource_cache.go
+++ b/resources/resource_cache.go
@@ -39,7 +39,7 @@ func newResourceCache(rs *Spec, memCache *dynacache.Cache) *ResourceCache {
cacheResources: dynacache.GetOrCreatePartition[string, resource.Resources](
memCache,
"/ress",
- dynacache.OptionsPartition{ClearWhen: dynacache.ClearOnChange, Weight: 40},
+ dynacache.OptionsPartition{ClearWhen: dynacache.ClearOnRebuild, Weight: 40},
),
cacheResourceTransformation: dynacache.GetOrCreatePartition[string, *resourceAdapterInner](
memCache,
diff --git a/resources/resource_factories/bundler/bundler.go b/resources/resource_factories/bundler/bundler.go
index c255da601..dd0f1a4e1 100644
--- a/resources/resource_factories/bundler/bundler.go
+++ b/resources/resource_factories/bundler/bundler.go
@@ -20,6 +20,7 @@ import (
"path"
"github.com/gohugoio/hugo/common/hugio"
+ "github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
@@ -86,13 +87,32 @@ func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resou
// The given set of resources must be of the same Media Type.
// We may improve on that in the future, but then we need to know more.
- for i, r := range r {
- if i > 0 && r.MediaType().Type != resolvedm.Type {
- return nil, fmt.Errorf("resources in Concat must be of the same Media Type, got %q and %q", r.MediaType().Type, resolvedm.Type)
+ for i, rr := range r {
+ if i > 0 && rr.MediaType().Type != resolvedm.Type {
+ return nil, fmt.Errorf("resources in Concat must be of the same Media Type, got %q and %q", rr.MediaType().Type, resolvedm.Type)
}
- resolvedm = r.MediaType()
+ resolvedm = rr.MediaType()
}
+ idm := c.rs.Cfg.NewIdentityManager("concat")
+ // Add the concatenated resources as dependencies to the composite resource
+ // so that we can track changes to the individual resources.
+ idm.AddIdentityForEach(identity.ForEeachIdentityProviderFunc(
+ func(f func(identity.Identity) bool) bool {
+ var terminate bool
+ for _, rr := range r {
+ identity.WalkIdentitiesShallow(rr, func(depth int, id identity.Identity) bool {
+ terminate = f(id)
+ return terminate
+ })
+ if terminate {
+ break
+ }
+ }
+ return terminate
+ },
+ ))
+
concatr := func() (hugio.ReadSeekCloser, error) {
var rcsources []hugio.ReadSeekCloser
for _, s := range r {
@@ -136,6 +156,7 @@ func (c *Client) Concat(targetPath string, r resource.Resources) (resource.Resou
LazyPublish: true,
OpenReadSeekCloser: concatr,
TargetPath: targetPath,
+ DependencyManager: idm,
})
if err != nil {
return nil, err
diff --git a/resources/resource_factories/create/create.go b/resources/resource_factories/create/create.go
index e98eb7425..0cf84c49b 100644
--- a/resources/resource_factories/create/create.go
+++ b/resources/resource_factories/create/create.go
@@ -63,13 +63,6 @@ func (c *Client) Copy(r resource.Resource, targetPath string) (resource.Resource
})
}
-func (c *Client) newDependencyManager() identity.Manager {
- if c.rs.Cfg.Running() {
- return identity.NewManager("resources")
- }
- return identity.NopManager
-}
-
// Get creates a new Resource by opening the given pathname in the assets filesystem.
func (c *Client) Get(pathname string) (resource.Resource, error) {
pathname = path.Clean(pathname)
@@ -79,7 +72,8 @@ func (c *Client) Get(pathname string) (resource.Resource, error) {
// The resource file will not be read before it gets used (e.g. in .Content),
// so we need to check that the file exists here.
filename := filepath.FromSlash(pathname)
- if _, err := c.rs.BaseFs.Assets.Fs.Stat(filename); err != nil {
+ fi, err := c.rs.BaseFs.Assets.Fs.Stat(filename)
+ if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
@@ -87,14 +81,16 @@ func (c *Client) Get(pathname string) (resource.Resource, error) {
return nil, err
}
+ pi := fi.(hugofs.FileMetaInfo).Meta().PathInfo
+
return c.rs.NewResource(resources.ResourceSourceDescriptor{
LazyPublish: true,
OpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {
return c.rs.BaseFs.Assets.Fs.Open(filename)
},
- GroupIdentity: identity.StringIdentity(key),
- DependencyManager: c.newDependencyManager(),
- TargetPath: pathname,
+ Path: pi,
+ GroupIdentity: pi,
+ TargetPath: pathname,
})
})
}