diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-31 09:58:46 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-31 09:58:46 +0700 |
| commit | 91fce8ab6ce4c6f9722ac2af15fca33600e45abf (patch) | |
| tree | e55ac2dcbc09989b8f7524617a439b6fcd3172ad | |
| parent | dcd3c7c73ca392fed1bfb0de16014ee7ab6fb5a7 (diff) | |
| download | pakakeh.go-91fce8ab6ce4c6f9722ac2af15fca33600e45abf.tar.xz | |
lib/memfs: remove unused parameter in isWatched and isIncluded
While at it change the isIncluded parameter from os.FileMode to
os.FileInfo.
| -rw-r--r-- | lib/memfs/memfs.go | 19 | ||||
| -rw-r--r-- | lib/memfs/memfs_test.go | 4 |
2 files changed, 10 insertions, 13 deletions
diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go index f0f3e5bd..eb2ee326 100644 --- a/lib/memfs/memfs.go +++ b/lib/memfs/memfs.go @@ -116,13 +116,12 @@ func (mfs *MemFS) AddChild(parent *Node, fi os.FileInfo) (child *Node, err error var ( logp = "AddChild" sysPath = filepath.Join(parent.SysPath, fi.Name()) - fiMode = fi.Mode() ) - if mfs.isExcluded(sysPath, fiMode) { + if mfs.isExcluded(sysPath) { return nil, nil } - if mfs.isWatched(sysPath, fiMode) { + if mfs.isWatched(sysPath) { child, err = parent.addChild(sysPath, fi, mfs.Opts.MaxFileSize) if err != nil { return nil, fmt.Errorf("%s %s: %w", logp, sysPath, err) @@ -130,7 +129,7 @@ func (mfs *MemFS) AddChild(parent *Node, fi os.FileInfo) (child *Node, err error mfs.PathNodes.Set(child.Path, child) } - if !mfs.isIncluded(sysPath, fiMode) { + if !mfs.isIncluded(sysPath, fi) { if child != nil { // The path being watched, but not included. // Set the generate function name to empty, to prevent @@ -459,7 +458,7 @@ func (mfs *MemFS) createRoot() error { // isExcluded will return true if the system path is excluded from being // watched or included. -func (mfs *MemFS) isExcluded(sysPath string, mode os.FileMode) bool { +func (mfs *MemFS) isExcluded(sysPath string) bool { var ( re *regexp.Regexp ) @@ -473,10 +472,9 @@ func (mfs *MemFS) isExcluded(sysPath string, mode os.FileMode) bool { // isIncluded will return true if the system path is filtered to be included, // pass the list of Includes regexp or no filter defined. -func (mfs *MemFS) isIncluded(sysPath string, mode os.FileMode) bool { +func (mfs *MemFS) isIncluded(sysPath string, fi os.FileInfo) bool { var ( re *regexp.Regexp - fi os.FileInfo err error ) @@ -489,21 +487,20 @@ func (mfs *MemFS) isIncluded(sysPath string, mode os.FileMode) bool { return true } } - if mode&os.ModeSymlink == os.ModeSymlink { + if fi.Mode()&os.ModeSymlink == os.ModeSymlink { // File is symlink, get the real FileInfo to check if its // directory or not. fi, err = os.Stat(sysPath) if err != nil { return false } - mode = fi.Mode() } - return mode.IsDir() + return fi.IsDir() } // isWatched will return true if the system path is filtered to be watched. -func (mfs *MemFS) isWatched(sysPath string, mode os.FileMode) bool { +func (mfs *MemFS) isWatched(sysPath string) bool { var ( re *regexp.Regexp ) diff --git a/lib/memfs/memfs_test.go b/lib/memfs/memfs_test.go index f61d2930..25affe0d 100644 --- a/lib/memfs/memfs_test.go +++ b/lib/memfs/memfs_test.go @@ -537,11 +537,11 @@ func TestMemFS_isIncluded(t *testing.T) { t.Fatal(err) } - got = mfs.isExcluded(sysPath, fi.Mode()) + got = mfs.isExcluded(sysPath) if got { test.Assert(t, sysPath, !c.exp[x], got) } else { - got = mfs.isIncluded(sysPath, fi.Mode()) + got = mfs.isIncluded(sysPath, fi) test.Assert(t, sysPath, c.exp[x], got) } } |
