allow notebook as hidden dir (#402)

pull/361/head
Tillman Jex 3 weeks 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
}
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 {

@ -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
// 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…
Cancel
Save