return errors.Wrap(err, "failed to load config")
}
+ s.Fs.Destination = hugofs.NewCreateCountingFs(s.Fs.Destination)
+
depsCfg := s.depsCfg
depsCfg.Fs = s.Fs
depsCfg.Cfg = s.Cfg
s.Assert(cfg.Height, qt.Equals, height)
}
+func (s *sitesBuilder) AssertNoDuplicateWrites() {
+ s.Helper()
+ d := s.Fs.Destination.(hugofs.DuplicatesReporter)
+ s.Assert(d.ReportDuplicates(), qt.Equals, "")
+}
+
func (s *sitesBuilder) FileContent(filename string) string {
s.T.Helper()
filename = filepath.FromSlash(filename)
}
func (l *genericResource) Publish() error {
- fr, err := l.ReadSeekCloser()
- if err != nil {
- return err
- }
- defer fr.Close()
+ var err error
+ l.publishInit.Do(func() {
+ var fr hugio.ReadSeekCloser
+ fr, err = l.ReadSeekCloser()
+ if err != nil {
+ return
+ }
+ defer fr.Close()
- fw, err := helpers.OpenFilesForWriting(l.spec.BaseFs.PublishFs, l.getTargetFilenames()...)
- if err != nil {
- return err
- }
- defer fw.Close()
+ var fw io.WriteCloser
+ fw, err = helpers.OpenFilesForWriting(l.spec.BaseFs.PublishFs, l.getTargetFilenames()...)
+ if err != nil {
+ return
+ }
+ defer fw.Close()
+
+ _, err = io.Copy(fw, fr)
+
+ })
- _, err = io.Copy(fw, fr)
return err
}
return &l
}
-// returns an opened file or nil if nothing to write.
-func (l *genericResource) openDestinationsForWriting() (io.WriteCloser, error) {
- targetFilenames := l.getTargetFilenames()
- var changedFilenames []string
+// returns an opened file or nil if nothing to write (it may already be published).
+func (l *genericResource) openDestinationsForWriting() (w io.WriteCloser, err error) {
+
+ l.publishInit.Do(func() {
+ targetFilenames := l.getTargetFilenames()
+ var changedFilenames []string
+
+ // Fast path:
+ // This is a processed version of the original;
+ // check if it already existis at the destination.
+ for _, targetFilename := range targetFilenames {
+ if _, err := l.getSpec().BaseFs.PublishFs.Stat(targetFilename); err == nil {
+ continue
+ }
- // Fast path:
- // This is a processed version of the original;
- // check if it already existis at the destination.
- for _, targetFilename := range targetFilenames {
- if _, err := l.getSpec().BaseFs.PublishFs.Stat(targetFilename); err == nil {
- continue
+ changedFilenames = append(changedFilenames, targetFilename)
}
- changedFilenames = append(changedFilenames, targetFilename)
- }
- if len(changedFilenames) == 0 {
- return nil, nil
- }
+ if len(changedFilenames) == 0 {
+ return
+ }
+
+ w, err = helpers.OpenFilesForWriting(l.getSpec().BaseFs.PublishFs, changedFilenames...)
+
+ })
+
+ return
- return helpers.OpenFilesForWriting(l.getSpec().BaseFs.PublishFs, changedFilenames...)
}
func (r *genericResource) openPublishFileForWriting(relTargetPath string) (io.WriteCloser, error) {
type resourceContent struct {
content string
contentInit sync.Once
+
+ publishInit sync.Once
}
type resourceFileInfo struct {