Skip to content

Commit

Permalink
Merge pull request #7 from ipfs/kevina/non-file-ignore
Browse files Browse the repository at this point in the history
Ignore non-directories in the top level directory.
  • Loading branch information
whyrusleeping authored Dec 7, 2016
2 parents 3567e09 + 7ec19f1 commit 9652294
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion flatfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
defer close(reschan)
err := fs.walkTopLevel(fs.path, reschan)
if err != nil {
log.Warning("walk failed: ", err)
reschan <- query.Result{Error: errors.New("walk failed: " + err.Error())}
}
}()
return query.ResultsWithChan(q, reschan), nil
Expand Down Expand Up @@ -357,6 +357,16 @@ func (fs *Datastore) walk(path string, reschan chan query.Result) error {
return err
}
defer dir.Close()

// ignore non-directories
fileInfo, err := dir.Stat()
if err != nil {
return err
}
if !fileInfo.IsDir() {
return nil
}

names, err := dir.Readdirnames(-1)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions flatfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ func testQuerySimple(dirFunc mkShardFunc, t *testing.T) {
temp, cleanup := tempdir(t)
defer cleanup()

err := ioutil.WriteFile(filepath.Join(temp, "README"), []byte("something"), 0666)
if err != nil {
t.Fatalf("WriteFile fail: %v\n", err)
}

fs, err := flatfs.New(temp, dirFunc(2), false)
if err != nil {
t.Fatalf("New fail: %v\n", err)
Expand Down

0 comments on commit 9652294

Please sign in to comment.