summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-03 20:40:20 +0700
committerShulhan <ms@kilabit.info>2022-08-03 20:40:20 +0700
commite87e437cd3a4fc043c2642a7211b2631f767f80c (patch)
tree70998c84c1e4575745bcb4f3f66019bb6890c660
parent7dd9858b2263a53179919da61e11c26d96fbfea7 (diff)
downloadpakakeh.go-e87e437cd3a4fc043c2642a7211b2631f767f80c.tar.xz
lib/memfs: simplify code by using return-first and else condition
-rw-r--r--lib/memfs/memfs.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go
index c1fccea9..019ffb33 100644
--- a/lib/memfs/memfs.go
+++ b/lib/memfs/memfs.go
@@ -241,18 +241,17 @@ func (mfs *MemFS) Get(path string) (node *Node, err error) {
node = mfs.PathNodes.Get(path)
if node == nil {
- if mfs.Opts.TryDirect {
- node, err = mfs.refresh(path)
- if err != nil {
- return nil, fmt.Errorf("%s: %s: %w", logp, path, err)
- }
- return node, nil
+ if !mfs.Opts.TryDirect {
+ return nil, os.ErrNotExist
}
- return nil, os.ErrNotExist
- }
- if mfs.Opts.TryDirect {
+ node, err = mfs.refresh(path)
+ if err != nil {
+ return nil, fmt.Errorf(`%s: %s: %w`, logp, path, err)
+ }
+ } else if mfs.Opts.TryDirect {
_ = node.Update(nil, mfs.Opts.MaxFileSize)
+
// Ignore error if the file is not exist in storage.
// Use case: the node maybe have been result of embed and the
// merged with other MemFS instance that use TryDirect flag.