Unexport private functions

This commit is contained in:
Deluan 2020-05-18 15:06:33 -04:00
parent 9e845cb116
commit a4183aea8c
2 changed files with 13 additions and 13 deletions

View File

@ -62,12 +62,12 @@ func (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated
return
}
for _, f := range files {
isDir, err := IsDirOrSymlinkToDir(dirPath, f)
isDir, err := isDirOrSymlinkToDir(dirPath, f)
// Skip invalid symlinks
if err != nil {
continue
}
if isDir && !IsDirIgnored(dirPath, f) {
if isDir && !isDirIgnored(dirPath, f) {
children = append(children, filepath.Join(dirPath, f.Name()))
} else {
if f.ModTime().After(lastUpdated) {
@ -78,12 +78,12 @@ func (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated
return
}
// IsDirOrSymlinkToDir returns true if and only if the dirent represents a file
// isDirOrSymlinkToDir returns true if and only if the dirent represents a file
// system directory, or a symbolic link to a directory. Note that if the dirent
// is not a directory but is a symbolic link, this method will resolve by
// sending a request to the operating system to follow the symbolic link.
// Copied from github.com/karrick/godirwalk
func IsDirOrSymlinkToDir(baseDir string, dirent os.FileInfo) (bool, error) {
func isDirOrSymlinkToDir(baseDir string, dirent os.FileInfo) (bool, error) {
if dirent.IsDir() {
return true, nil
}
@ -98,7 +98,7 @@ func IsDirOrSymlinkToDir(baseDir string, dirent os.FileInfo) (bool, error) {
return dirent.IsDir(), nil
}
func IsDirIgnored(baseDir string, dirent os.FileInfo) bool {
func isDirIgnored(baseDir string, dirent os.FileInfo) bool {
_, err := os.Stat(filepath.Join(baseDir, dirent.Name(), consts.SkipScanFile))
return err == nil
}

View File

@ -111,34 +111,34 @@ var _ = Describe("ChangeDetector", func() {
Expect(changed).To(ConsistOf(P("a/b")))
})
Describe("IsDirOrSymlinkToDir", func() {
Describe("isDirOrSymlinkToDir", func() {
It("returns true for normal dirs", func() {
dir, _ := os.Stat("tests/fixtures")
Expect(IsDirOrSymlinkToDir("tests", dir)).To(BeTrue())
Expect(isDirOrSymlinkToDir("tests", dir)).To(BeTrue())
})
It("returns true for symlinks to dirs", func() {
dir, _ := os.Stat("tests/fixtures/symlink2dir")
Expect(IsDirOrSymlinkToDir("tests/fixtures", dir)).To(BeTrue())
Expect(isDirOrSymlinkToDir("tests/fixtures", dir)).To(BeTrue())
})
It("returns false for files", func() {
dir, _ := os.Stat("tests/fixtures/test.mp3")
Expect(IsDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
Expect(isDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
})
It("returns false for symlinks to files", func() {
dir, _ := os.Stat("tests/fixtures/symlink")
Expect(IsDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
Expect(isDirOrSymlinkToDir("tests/fixtures", dir)).To(BeFalse())
})
})
Describe("IsDirIgnored", func() {
Describe("isDirIgnored", func() {
baseDir := filepath.Join("tests", "fixtures")
It("returns false for normal dirs", func() {
dir, _ := os.Stat(filepath.Join(baseDir, "empty_folder"))
Expect(IsDirIgnored(baseDir, dir)).To(BeFalse())
Expect(isDirIgnored(baseDir, dir)).To(BeFalse())
})
It("returns true when folder contains .ndignore file", func() {
dir, _ := os.Stat(filepath.Join(baseDir, "ignored_folder"))
Expect(IsDirIgnored(baseDir, dir)).To(BeTrue())
Expect(isDirIgnored(baseDir, dir)).To(BeTrue())
})
})
})