summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-03-27 15:45:10 +0700
committerShulhan <ms@kilabit.info>2022-03-27 17:01:43 +0700
commit6934a428bf1027524aae7e1fd96bdf7f5e0dbe98 (patch)
treec5d8306ff3c3d14ea1ef62a43f0c074473aa8a3a
parent4eb8d7019fa230ebf575d32d93c692146b55c324 (diff)
downloadpakakeh.go-6934a428bf1027524aae7e1fd96bdf7f5e0dbe98.tar.xz
lib/memfs: check for possible nil on Get
In case the instance of memfs is set to nil (for example, the root directory being watched is deleted on DirWatcher), the Get method will cause panic after the next update on content of root directory.
-rw-r--r--lib/memfs/memfs.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go
index a1cfa331..764e2413 100644
--- a/lib/memfs/memfs.go
+++ b/lib/memfs/memfs.go
@@ -211,6 +211,10 @@ func (mfs *MemFS) AddFile(internalPath, externalPath string) (node *Node, err er
func (mfs *MemFS) Get(path string) (node *Node, err error) {
logp := "Get"
+ if mfs == nil || mfs.PathNodes == nil {
+ return nil, fmt.Errorf("%s %s: %w", logp, path, os.ErrNotExist)
+ }
+
node = mfs.PathNodes.Get(path)
if node == nil {
if mfs.Opts.Development {