allow notebook as hidden dir (#402)

pull/361/head
Tillman Jex 1 month ago committed by GitHub
parent 45b68121ce
commit 0973f9929d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -150,7 +150,8 @@ func (t *indexTask) execute(callback func(change paths.DiffChange)) (NoteIndexin
return false, nil 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() target, err := t.index.IndexedPaths()
if err != nil { if err != nil {

@ -0,0 +1 @@
this is a hidden file, and should not be indexed / walked.

@ -10,7 +10,7 @@ import (
// Walk emits the metadata of each file stored in the directory if they pass // Walk emits the metadata of each file stored in the directory if they pass
// the given shouldIgnorePath closure. Hidden files and directories are ignored. // 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) c := make(chan Metadata, 50)
go func() { go func() {
defer close(c) defer close(c)
@ -22,9 +22,10 @@ func Walk(basePath string, logger util.Logger, shouldIgnorePath func(string) (bo
filename := info.Name() filename := info.Name()
isHidden := strings.HasPrefix(filename, ".") isHidden := strings.HasPrefix(filename, ".")
isNotebookRoot := filename == notebookRoot
if info.IsDir() { if info.IsDir() {
if isHidden { if isHidden && !isNotebookRoot {
return filepath.SkipDir return filepath.SkipDir
} }

@ -16,8 +16,38 @@ func TestWalk(t *testing.T) {
return filepath.Ext(path) != ".md", nil return filepath.Ext(path) != ".md", nil
} }
notebookRoot := filepath.Base(path)
actual := make([]string, 0) 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) assert.NotNil(t, m.Modified)
actual = append(actual, m.Path) actual = append(actual, m.Path)
} }

Loading…
Cancel
Save