mirror of
https://github.com/mickael-menu/zk
synced 2024-11-11 07:10:25 +00:00
allow notebook as hidden dir (#402)
This commit is contained in:
parent
45b68121ce
commit
0973f9929d
@ -150,7 +150,8 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
|
||||
return false, nil
|
||||
}
|
||||
|
||||
source := paths.Walk(t.path, t.logger, shouldIgnorePath)
|
||||
notebookPath := &NotebookPath{Path: t.path}
|
||||
source := paths.Walk(t.path, t.logger, notebookPath.Filename(), shouldIgnorePath)
|
||||
|
||||
target, err := t.index.IndexedPaths()
|
||||
if err != nil {
|
||||
|
1
internal/util/paths/testdata/.walk-hidden/.hidden-dir/.hidden-file-in-hidden-dir
vendored
Normal file
1
internal/util/paths/testdata/.walk-hidden/.hidden-dir/.hidden-file-in-hidden-dir
vendored
Normal file
@ -0,0 +1 @@
|
||||
this is a hidden file, and should not be indexed / walked.
|
0
internal/util/paths/testdata/.walk-hidden/.hidden-file-at-root
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/.hidden-file-at-root
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/Dir3/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/Dir3/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/b.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/b.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1 a space/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1 a space/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/.ignored.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/.ignored.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/.ignored/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/.ignored/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/b.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/b.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/dir1/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/dir1/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/ignored.txt
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir1/ignored.txt
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir2/a.md
vendored
Normal file
0
internal/util/paths/testdata/.walk-hidden/dir2/a.md
vendored
Normal file
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// Walk emits the metadata of each file stored in the directory if they pass
|
||||
// the given shouldIgnorePath closure. Hidden files and directories are ignored.
|
||||
func Walk(basePath string, logger util.Logger, shouldIgnorePath func(string) (bool, error)) <-chan Metadata {
|
||||
func Walk(basePath string, logger util.Logger, notebookRoot string, shouldIgnorePath func(string) (bool, error)) <-chan Metadata {
|
||||
c := make(chan Metadata, 50)
|
||||
go func() {
|
||||
defer close(c)
|
||||
@ -22,9 +22,10 @@ func Walk(basePath string, logger util.Logger, shouldIgnorePath func(string) (bo
|
||||
|
||||
filename := info.Name()
|
||||
isHidden := strings.HasPrefix(filename, ".")
|
||||
isNotebookRoot := filename == notebookRoot
|
||||
|
||||
if info.IsDir() {
|
||||
if isHidden {
|
||||
if isHidden && !isNotebookRoot {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,38 @@ func TestWalk(t *testing.T) {
|
||||
return filepath.Ext(path) != ".md", nil
|
||||
}
|
||||
|
||||
notebookRoot := filepath.Base(path)
|
||||
actual := make([]string, 0)
|
||||
for m := range Walk(path, &util.NullLogger, shouldIgnore) {
|
||||
for m := range Walk(path, &util.NullLogger, notebookRoot, shouldIgnore) {
|
||||
assert.NotNil(t, m.Modified)
|
||||
actual = append(actual, m.Path)
|
||||
}
|
||||
|
||||
assert.Equal(t, actual, []string{
|
||||
"Dir3/a.md",
|
||||
"a.md",
|
||||
"b.md",
|
||||
"dir1/a.md",
|
||||
"dir1/b.md",
|
||||
"dir1/dir1/a.md",
|
||||
"dir1 a space/a.md",
|
||||
"dir2/a.md",
|
||||
})
|
||||
}
|
||||
|
||||
// Walk should ignore all hidden files and dirs (prefixed with "."), with
|
||||
// exception of the notebook's root dir; i.e the root dir is allowed to be
|
||||
// hidden.
|
||||
func TestWalkHidden(t *testing.T) {
|
||||
var path = fixtures.Path(".walk-hidden")
|
||||
|
||||
shouldIgnore := func(path string) (bool, error) {
|
||||
return filepath.Ext(path) != ".md", nil
|
||||
}
|
||||
|
||||
notebookRoot := filepath.Base(path)
|
||||
actual := make([]string, 0)
|
||||
for m := range Walk(path, &util.NullLogger, notebookRoot, shouldIgnore) {
|
||||
assert.NotNil(t, m.Modified)
|
||||
actual = append(actual, m.Path)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user