summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-03-01 01:54:59 +0700
committerShulhan <ms@kilabit.info>2022-03-01 01:54:59 +0700
commit8f0a22c2f5e9ab5d11571650dbd49018dcf642b0 (patch)
tree10d705650734cf213edd4eac89306979ad11c125
parentde8a9f01a9859fbfc2145dabaf3fe97c13d01188 (diff)
downloadpakakeh.go-8f0a22c2f5e9ab5d11571650dbd49018dcf642b0.tar.xz
lib/memfs: make the GoEmbed re-mount the Root before generate Go file
Previously, we assume that the PathNodes from instance of MemFS is already up to date. If PathNodes is initialized by previous GoEmbed and the Root directory contains new files or directories, that new files does not get embedded. This changes fix this issue by force re-mount the whole Root directory before generating the Go file.
-rw-r--r--lib/memfs/embed.go6
-rw-r--r--lib/memfs/internal/test/embed/embed_test.go3
-rw-r--r--lib/memfs/internal/test/embed_disable_modtime/embed_test.go1
-rw-r--r--lib/memfs/memfs.go7
4 files changed, 17 insertions, 0 deletions
diff --git a/lib/memfs/embed.go b/lib/memfs/embed.go
index 9e16f6ef..8409d404 100644
--- a/lib/memfs/embed.go
+++ b/lib/memfs/embed.go
@@ -37,6 +37,12 @@ func (mfs *MemFS) GoEmbed() (err error) {
if len(mfs.Opts.Embed.GoFileName) == 0 {
mfs.Opts.Embed.GoFileName = DefaultEmbedGoFileName
}
+
+ err = mfs.remount()
+ if err != nil {
+ return fmt.Errorf("%s: %w", logp, err)
+ }
+
genData := &generateData{
Opts: mfs.Opts,
PathNode: mfs.PathNodes,
diff --git a/lib/memfs/internal/test/embed/embed_test.go b/lib/memfs/internal/test/embed/embed_test.go
index b7225081..ddffb95a 100644
--- a/lib/memfs/internal/test/embed/embed_test.go
+++ b/lib/memfs/internal/test/embed/embed_test.go
@@ -299,6 +299,9 @@ func init() {
`.*/node_save$`,
},
Embed: memfs.EmbedOptions{
+ CommentHeader: `// SPDX-FileCopyrightText: 2022 Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: AGPL-3.0-or-later
+`,
PackageName: "embed",
VarName: "memFS",
GoFileName: "./internal/test/embed/embed_test.go",
diff --git a/lib/memfs/internal/test/embed_disable_modtime/embed_test.go b/lib/memfs/internal/test/embed_disable_modtime/embed_test.go
index 7790f70e..42002c48 100644
--- a/lib/memfs/internal/test/embed_disable_modtime/embed_test.go
+++ b/lib/memfs/internal/test/embed_disable_modtime/embed_test.go
@@ -280,6 +280,7 @@ func init() {
`.*/node_save$`,
},
Embed: memfs.EmbedOptions{
+ CommentHeader: ``,
PackageName: "embed",
VarName: "memFS",
GoFileName: "./internal/test/embed_disable_modtime/embed_test.go",
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go
index da1e6475..59cbe234 100644
--- a/lib/memfs/memfs.go
+++ b/lib/memfs/memfs.go
@@ -509,6 +509,13 @@ func (mfs *MemFS) mount() (err error) {
return nil
}
+// remount reset the memfs to scanning the files again.
+func (mfs *MemFS) remount() (err error) {
+ mfs.Root = nil
+ mfs.PathNodes = nil
+ return mfs.mount()
+}
+
// scanDir scan the directory node for files and add them to memory file
// system.
// It returns number of childs added to the node or an error.