Skip to content

Commit

Permalink
Replace all usage of CopyOnWriteFs with OverlayFs
Browse files Browse the repository at this point in the history
Fixes #9761
  • Loading branch information
bep committed Apr 10, 2022
1 parent 3117e58 commit 30c2e54
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 258 deletions.
2 changes: 1 addition & 1 deletion create/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func TestNewContentFromFile(t *testing.T) {
cfg, fs := newTestCfg(c, mm)
h, err := hugolib.NewHugoSites(deps.DepsCfg{Cfg: cfg, Fs: fs})
c.Assert(err, qt.IsNil)

err = create.NewContent(h, cas.kind, cas.path)

if b, ok := cas.expected.(bool); ok && !b {
Expand All @@ -98,6 +97,7 @@ func TestNewContentFromFile(t *testing.T) {
if !strings.HasPrefix(fname, "content") {
fname = filepath.Join("content", fname)
}

content := readFileFromFs(c, fs.Source, fname)

for _, v := range cas.expected.([]string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/bep/godartsass v0.14.0
github.com/bep/golibsass v1.0.0
github.com/bep/gowebp v0.1.0
github.com/bep/overlayfs v0.1.0
github.com/bep/overlayfs v0.4.0
github.com/bep/tmc v0.5.1
github.com/clbanning/mxj/v2 v2.5.5
github.com/cli/safeexec v1.0.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ github.com/bep/gowebp v0.1.0 h1:4/iQpfnxHyXs3x/aTxMMdOpLEQQhFmF6G7EieWPTQyo=
github.com/bep/gowebp v0.1.0/go.mod h1:ZhFodwdiFp8ehGJpF4LdPl6unxZm9lLFjxD3z2h2AgI=
github.com/bep/overlayfs v0.1.0 h1:1hOCrvS4E5Hf0qwxM7m+9oitqClD9mRjQ1d4pECsVcU=
github.com/bep/overlayfs v0.1.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
github.com/bep/overlayfs v0.2.0 h1:JSJbbXLi0FRHtadJCmUNvaFWEAZhpDbX1nLNiKviECM=
github.com/bep/overlayfs v0.2.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
github.com/bep/overlayfs v0.3.0 h1:Vufu7kg4ehDJcjOaLTSiZI0F6tSF0Aqt0AWRi44DzSg=
github.com/bep/overlayfs v0.3.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
github.com/bep/overlayfs v0.4.0 h1:J/G5YltfU2BxO2KV/VcFzJo94jpRMjtthRNEZ+7V7uA=
github.com/bep/overlayfs v0.4.0/go.mod h1:NFjSmn3kCqG7KX2Lmz8qT8VhPPCwZap3UNogXawoQHM=
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg=
Expand Down
81 changes: 0 additions & 81 deletions hugofs/language_composite_fs.go

This file was deleted.

39 changes: 39 additions & 0 deletions hugofs/language_merge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package hugofs

import (
"os"
)

// LanguageDirsMerger implements the overlayfs.DirsMerger func, which is used
// to merge two directories.
var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) []os.FileInfo {
for _, fi1 := range bofi {
fim1 := fi1.(FileMetaInfo)
var found bool
for _, fi2 := range lofi {
fim2 := fi2.(FileMetaInfo)
if fi1.Name() == fi2.Name() && fim1.Meta().Lang == fim2.Meta().Lang {
found = true
break
}
}
if !found {
lofi = append(lofi, fi1)
}
}

return lofi
}
8 changes: 4 additions & 4 deletions hugofs/noop_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func (fs noOpFs) Create(name string) (afero.File, error) {
}

func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
return errNoOp
return nil
}

func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
return errNoOp
return nil
}

func (fs noOpFs) Open(name string) (afero.File, error) {
Expand All @@ -54,11 +54,11 @@ func (fs noOpFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File,
}

func (fs noOpFs) Remove(name string) error {
return errNoOp
return nil
}

func (fs noOpFs) RemoveAll(path string) error {
return errNoOp
return nil
}

func (fs noOpFs) Rename(oldname string, newname string) error {
Expand Down
1 change: 1 addition & 0 deletions hugolib/content_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func (f ContentFactory) SectionFromFilename(filename string) (string, error) {
func (f ContentFactory) CreateContentPlaceHolder(filename string) (string, error) {
filename = filepath.Clean(filename)
_, abs, err := f.h.AbsProjectContentDir(filename)

if err != nil {
return "", err
}
Expand Down
32 changes: 32 additions & 0 deletions hugolib/datafiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@ import (
qt "github.com/frankban/quicktest"
)

func TestDataFromTheme(t *testing.T) {
t.Parallel()

files := `
-- config.toml --
[module]
[[module.imports]]
path = "mytheme"
-- data/a.toml --
d1 = "d1main"
d2 = "d2main"
-- themes/mytheme/data/a.toml --
d1 = "d1theme"
d2 = "d2theme"
d3 = "d3theme"
-- layouts/index.html --
d1: {{ site.Data.a.d1 }}|d2: {{ site.Data.a.d2 }}|d3: {{ site.Data.a.d3 }}
`

b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()

b.AssertFileContent("public/index.html", `
d1: d1main|d2: d2main|d3: d3theme
`)
}

func TestDataDir(t *testing.T) {
t.Parallel()
equivDataDirs := make([]dataDir, 3)
Expand Down

0 comments on commit 30c2e54

Please sign in to comment.