diff options
author | satotake <doublequotation@gmail.com> | 2022-05-23 02:14:17 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-24 13:57:23 +0200 |
commit | 6f7fbe03b1a70733f00da6556a89250a29e53ec8 (patch) | |
tree | b00220561191a7ca0262a88acb5b572e29a55b32 /hugolib | |
parent | 2fc2e9c8718db2fe60f03bcf3661f449851cfe5f (diff) |
basefs: add `noBuildLock` flag
If the flag is enabled, `.hugo_build.lock` will not be created.
This ensures safe running on read-only filesystem etc.
Close #9780
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/filesystems/basefs.go | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index 2447246d6..a380857cd 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -76,18 +76,24 @@ type BaseFs struct { theBigFs *filesystemsCollector // Locks. - buildMu *lockedfile.Mutex // <project>/.hugo_build.lock - buildMuTests sync.Mutex // Used in tests. + buildMu Lockable // <project>/.hugo_build.lock +} + +type Lockable interface { + Lock() (unlock func(), err error) +} + +type fakeLockfileMutex struct { + mu sync.Mutex +} + +func (f *fakeLockfileMutex) Lock() (func(), error) { + f.mu.Lock() + return func() { f.mu.Unlock() }, nil } // Tries to acquire a build lock. func (fs *BaseFs) LockBuild() (unlock func(), err error) { - if htesting.IsTest { - fs.buildMuTests.Lock() - return func() { - fs.buildMuTests.Unlock() - }, nil - } return fs.buildMu.Lock() } @@ -445,12 +451,19 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir)) publishFsStatic := fs.PublishDirStatic + var buildMu Lockable + if p.Cfg.GetBool("noBuildLock") || htesting.IsTest { + buildMu = &fakeLockfileMutex{} + } else { + buildMu = lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)) + } + b := &BaseFs{ SourceFs: sourceFs, WorkDir: fs.WorkingDirReadOnly, PublishFs: publishFs, PublishFsStatic: publishFsStatic, - buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)), + buildMu: buildMu, } for _, opt := range options { |