aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
Diffstat (limited to 'resources')
-rw-r--r--resources/resource.go55
-rw-r--r--resources/resource_spec.go18
2 files changed, 24 insertions, 49 deletions
diff --git a/resources/resource.go b/resources/resource.go
index e78dd12cb..6bef1b275 100644
--- a/resources/resource.go
+++ b/resources/resource.go
@@ -343,7 +343,7 @@ func GetTestInfoForResource(r resource.Resource) GenericResourceTestInfo {
// genericResource represents a generic linkable resource.
type genericResource struct {
- *resourceContent
+ publishInit *sync.Once
sd ResourceSourceDescriptor
paths internal.ResourcePaths
@@ -412,11 +412,18 @@ func (l *genericResource) cloneTo(targetPath string) resource.Resource {
}
func (l *genericResource) Content(context.Context) (any, error) {
- if err := l.initContent(); err != nil {
- return nil, err
+ r, err := l.ReadSeekCloser()
+ if err != nil {
+ return "", err
}
+ defer r.Close()
- return l.content, nil
+ var b []byte
+ b, err = io.ReadAll(r)
+ if err != nil {
+ return "", err
+ }
+ return string(b), nil
}
func (r *genericResource) Err() resource.ResourceError {
@@ -527,28 +534,6 @@ func (l *genericResource) Title() string {
return l.title
}
-func (l *genericResource) initContent() error {
- var err error
- l.contentInit.Do(func() {
- var r hugio.ReadSeekCloser
- r, err = l.ReadSeekCloser()
- if err != nil {
- return
- }
- defer r.Close()
-
- var b []byte
- b, err = io.ReadAll(r)
- if err != nil {
- return
- }
-
- l.content = string(b)
- })
-
- return err
-}
-
func (l *genericResource) getSpec() *Spec {
return l.spec
}
@@ -588,12 +573,9 @@ func (rc *genericResource) cloneWithUpdates(u *transformationUpdate) (baseResour
r := rc.clone()
if u.content != nil {
- r.contentInit.Do(func() {
- r.content = *u.content
- r.sd.OpenReadSeekCloser = func() (hugio.ReadSeekCloser, error) {
- return hugio.NewReadSeekerNoOpCloserFromString(r.content), nil
- }
- })
+ r.sd.OpenReadSeekCloser = func() (hugio.ReadSeekCloser, error) {
+ return hugio.NewReadSeekerNoOpCloserFromString(*u.content), nil
+ }
}
r.sd.MediaType = u.mediaType
@@ -620,7 +602,7 @@ func (rc *genericResource) cloneWithUpdates(u *transformationUpdate) (baseResour
}
func (l genericResource) clone() *genericResource {
- l.resourceContent = &resourceContent{}
+ l.publishInit = &sync.Once{}
return &l
}
@@ -633,13 +615,6 @@ type targetPather interface {
TargetPath() string
}
-type resourceContent struct {
- content string
- contentInit sync.Once
-
- publishInit sync.Once
-}
-
type resourceHash struct {
value string
size int64
diff --git a/resources/resource_spec.go b/resources/resource_spec.go
index 66f56d147..5fdcdd831 100644
--- a/resources/resource_spec.go
+++ b/resources/resource_spec.go
@@ -163,15 +163,15 @@ func (r *Spec) NewResource(rd ResourceSourceDescriptor) (resource.Resource, erro
}
gr := &genericResource{
- Staler: &AtomicStaler{},
- h: &resourceHash{},
- paths: rp,
- spec: r,
- sd: rd,
- params: make(map[string]any),
- name: rd.Name,
- title: rd.Name,
- resourceContent: &resourceContent{},
+ Staler: &AtomicStaler{},
+ h: &resourceHash{},
+ publishInit: &sync.Once{},
+ paths: rp,
+ spec: r,
+ sd: rd,
+ params: make(map[string]any),
+ name: rd.Name,
+ title: rd.Name,
}
if rd.MediaType.MainType == "image" {