diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-03-11 09:48:20 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-03-11 13:10:47 +0100 |
commit | 64b7b7a89753a39661219b2fcb92d7f185a03f63 (patch) | |
tree | fc0a936c03faffd4acfd28b4997f499e4109dcfb | |
parent | 5ef8a9f32c25a9b4cc821393c58733e57a7ad234 (diff) | |
download | hugo-64b7b7a89753a39661219b2fcb92d7f185a03f63.tar.gz hugo-64b7b7a89753a39661219b2fcb92d7f185a03f63.zip |
Revert "Allow rendering static files to disk and dynamic to memory in server mode"
This reverts commit 7d8011ed63d587b87a7c182748914fe146590093.
Updates #9647
-rw-r--r-- | commands/commandeer.go | 14 | ||||
-rw-r--r-- | commands/hugo.go | 3 | ||||
-rw-r--r-- | commands/server.go | 23 | ||||
-rw-r--r-- | commands/static_syncer.go | 9 | ||||
-rw-r--r-- | hugofs/fs.go | 12 | ||||
-rw-r--r-- | hugolib/filesystems/basefs.go | 13 | ||||
-rw-r--r-- | hugolib/pages_process.go | 16 | ||||
-rw-r--r-- | hugolib/site.go | 4 |
8 files changed, 25 insertions, 69 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 07181f244..bf42501e0 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -92,7 +92,6 @@ type commandeer struct { languagesConfigured bool languages langs.Languages doLiveReload bool - renderStaticToDisk bool fastRenderMode bool showErrorInBrowser bool wasError bool @@ -369,9 +368,8 @@ func (c *commandeer) loadConfig() error { } createMemFs := config.GetBool("renderToMemory") - c.renderStaticToDisk = config.GetBool("renderStaticToDisk") - if createMemFs && !c.renderStaticToDisk { + if createMemFs { // Rendering to memoryFS, publish to Root regardless of publishDir. config.Set("publishDir", "/") } @@ -382,14 +380,6 @@ func (c *commandeer) loadConfig() error { if c.destinationFs != nil { // Need to reuse the destination on server rebuilds. fs.Destination = c.destinationFs - } else if createMemFs && c.renderStaticToDisk { - // Writes the dynamic output on memory, - // while serve others directly from publishDir - publishDir := config.GetString("publishDir") - writableFs := afero.NewBasePathFs(afero.NewMemMapFs(), publishDir) - publicFs := afero.NewOsFs() - fs.Destination = afero.NewCopyOnWriteFs(afero.NewReadOnlyFs(publicFs), writableFs) - fs.DestinationStatic = publicFs } else if createMemFs { // Hugo writes the output to memory instead of the disk. fs.Destination = new(afero.MemMapFs) @@ -407,13 +397,11 @@ func (c *commandeer) loadConfig() error { changeDetector.PrepareNew() fs.Destination = hugofs.NewHashingFs(fs.Destination, changeDetector) - fs.DestinationStatic = hugofs.NewHashingFs(fs.DestinationStatic, changeDetector) c.changeDetector = changeDetector } if c.Cfg.GetBool("logPathWarnings") { fs.Destination = hugofs.NewCreateCountingFs(fs.Destination) - fs.DestinationStatic = hugofs.NewCreateCountingFs(fs.DestinationStatic) } // To debug hard-to-find path issues. diff --git a/commands/hugo.go b/commands/hugo.go index 21140fa43..8c5294f00 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -652,9 +652,6 @@ func (c *commandeer) copyStaticTo(sourceFs *filesystems.SourceFilesystem) (uint6 syncer.ChmodFilter = chmodFilter syncer.SrcFs = fs syncer.DestFs = c.Fs.Destination - if c.renderStaticToDisk { - syncer.DestFs = c.Fs.DestinationStatic - } // Now that we are using a unionFs for the static directories // We can effectively clean the publishDir on initial sync syncer.Delete = c.Cfg.GetBool("cleanDestinationDir") diff --git a/commands/server.go b/commands/server.go index 3f5290816..7d9462b36 100644 --- a/commands/server.go +++ b/commands/server.go @@ -48,16 +48,15 @@ type serverCmd struct { // Can be used to stop the server. Useful in tests stop <-chan bool - disableLiveReload bool - navigateToChanged bool - renderToDisk bool - renderStaticToDisk bool - serverAppend bool - serverInterface string - serverPort int - liveReloadPort int - serverWatch bool - noHTTPCache bool + disableLiveReload bool + navigateToChanged bool + renderToDisk bool + serverAppend bool + serverInterface string + serverPort int + liveReloadPort int + serverWatch bool + noHTTPCache bool disableFastRender bool disableBrowserError bool @@ -102,7 +101,6 @@ of a second, you will be able to save and see your changes nearly instantly.`, cc.cmd.Flags().BoolVar(&cc.renderToDisk, "renderToDisk", false, "render to Destination path (default is render to memory & serve from there)") cc.cmd.Flags().BoolVar(&cc.disableFastRender, "disableFastRender", false, "enables full re-renders on changes") cc.cmd.Flags().BoolVar(&cc.disableBrowserError, "disableBrowserError", false, "do not show build errors in the browser") - cc.cmd.Flags().BoolVar(&cc.renderStaticToDisk, "renderStaticToDisk", false, "render static files to disk but dynamic files render to memory.") cc.cmd.Flags().String("memstats", "", "log memory usage to this file") cc.cmd.Flags().String("meminterval", "100ms", "interval to poll memory usage (requires --memstats), valid time units are \"ns\", \"us\" (or \"µs\"), \"ms\", \"s\", \"m\", \"h\".") @@ -143,7 +141,6 @@ func (sc *serverCmd) server(cmd *cobra.Command, args []string) error { cfgInit := func(c *commandeer) error { c.Set("renderToMemory", !sc.renderToDisk) - c.Set("renderStaticToDisk", sc.renderStaticToDisk) if cmd.Flags().Changed("navigateToChanged") { c.Set("navigateToChanged", sc.navigateToChanged) } @@ -335,8 +332,6 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, string, string, erro if i == 0 { if f.s.renderToDisk { jww.FEEDBACK.Println("Serving pages from " + absPublishDir) - } else if f.s.renderStaticToDisk { - jww.FEEDBACK.Println("Serving pages from memory and static files from " + absPublishDir) } else { jww.FEEDBACK.Println("Serving pages from memory") } diff --git a/commands/static_syncer.go b/commands/static_syncer.go index 2eb2b6662..5569d4de6 100644 --- a/commands/static_syncer.go +++ b/commands/static_syncer.go @@ -56,9 +56,6 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error { syncer.ChmodFilter = chmodFilter syncer.SrcFs = sourceFs.Fs syncer.DestFs = c.Fs.Destination - if c.renderStaticToDisk { - syncer.DestFs = c.Fs.DestinationStatic - } // prevent spamming the log on changes logger := helpers.NewDistinctErrorLogger() @@ -104,11 +101,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error { toRemove := filepath.Join(publishDir, relPath) logger.Println("File no longer exists in static dir, removing", toRemove) - if c.renderStaticToDisk { - _ = c.Fs.DestinationStatic.RemoveAll(toRemove) - } else { - _ = c.Fs.Destination.RemoveAll(toRemove) - } + _ = c.Fs.Destination.RemoveAll(toRemove) } else if err == nil { // If file still exists, sync it logger.Println("Syncing", relPath, "to", publishDir) diff --git a/hugofs/fs.go b/hugofs/fs.go index 95645204e..54d962553 100644 --- a/hugofs/fs.go +++ b/hugofs/fs.go @@ -35,9 +35,6 @@ type Fs struct { // Destination is Hugo's destination file system. Destination afero.Fs - // Destination used for `renderStaticToDisk` - DestinationStatic afero.Fs - // Os is an OS file system. // NOTE: Field is currently unused. Os afero.Fs @@ -72,11 +69,10 @@ func NewFrom(fs afero.Fs, cfg config.Provider) *Fs { func newFs(base afero.Fs, cfg config.Provider) *Fs { return &Fs{ - Source: base, - Destination: base, - DestinationStatic: base, - Os: &afero.OsFs{}, - WorkingDir: getWorkingDirFs(base, cfg), + Source: base, + Destination: base, + Os: &afero.OsFs{}, + WorkingDir: getWorkingDirFs(base, cfg), } } diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 1614bd0b3..2e32932c6 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -71,9 +71,6 @@ type BaseFs struct { // A read-only filesystem starting from the project workDir. WorkDir afero.Fs - // The filesystem used for renderStaticToDisk. - PublishFsStatic afero.Fs - theBigFs *filesystemsCollector // Locks. @@ -441,17 +438,15 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err publishFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Destination, p.AbsPublishDir)) sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir)) - publishFsStatic := afero.NewBasePathFs(fs.Source, p.AbsPublishDir) // Same as sourceFs, but no decoration. This is what's used by os.ReadDir etc. workDir := afero.NewBasePathFs(afero.NewReadOnlyFs(fs.Source), p.WorkingDir) b := &BaseFs{ - SourceFs: sourceFs, - WorkDir: workDir, - PublishFs: publishFs, - PublishFsStatic: publishFsStatic, - buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)), + SourceFs: sourceFs, + WorkDir: workDir, + PublishFs: publishFs, + buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)), } for _, opt := range options { diff --git a/hugolib/pages_process.go b/hugolib/pages_process.go index 59b20dabc..541c0ae3e 100644 --- a/hugolib/pages_process.go +++ b/hugolib/pages_process.go @@ -33,10 +33,9 @@ func newPagesProcessor(h *HugoSites, sp *source.SourceSpec) *pagesProcessor { procs := make(map[string]pagesCollectorProcessorProvider) for _, s := range h.Sites { procs[s.Lang()] = &sitePagesProcessor{ - m: s.pageMap, - errorSender: s.h, - itemChan: make(chan interface{}, config.GetNumWorkerMultiplier()*2), - renderStaticToDisk: h.Cfg.GetBool("renderStaticToDisk"), + m: s.pageMap, + errorSender: s.h, + itemChan: make(chan interface{}, config.GetNumWorkerMultiplier()*2), } } return &pagesProcessor{ @@ -119,8 +118,6 @@ type sitePagesProcessor struct { ctx context.Context itemChan chan interface{} itemGroup *errgroup.Group - - renderStaticToDisk bool } func (p *sitePagesProcessor) Process(item interface{}) error { @@ -165,12 +162,7 @@ func (p *sitePagesProcessor) copyFile(fim hugofs.FileMetaInfo) error { defer f.Close() - fs := s.PublishFs - if p.renderStaticToDisk { - fs = s.PublishFsStatic - } - - return s.publish(&s.PathSpec.ProcessingStats.Files, target, f, fs) + return s.publish(&s.PathSpec.ProcessingStats.Files, target, f) } func (p *sitePagesProcessor) doProcess(item interface{}) error { diff --git a/hugolib/site.go b/hugolib/site.go index 0b8e807dd..c76bdc141 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1824,10 +1824,10 @@ func (s *Site) lookupTemplate(layouts ...string) (tpl.Template, bool) { return nil, false } -func (s *Site) publish(statCounter *uint64, path string, r io.Reader, fs afero.Fs) (err error) { +func (s *Site) publish(statCounter *uint64, path string, r io.Reader) (err error) { s.PathSpec.ProcessingStats.Incr(statCounter) - return helpers.WriteToDisk(filepath.Clean(path), r, fs) + return helpers.WriteToDisk(filepath.Clean(path), r, s.BaseFs.PublishFs) } func (s *Site) kindFromFileInfoOrSections(fi *fileInfo, sections []string) string { |