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 return
} }
for _, f := range files { for _, f := range files {
isDir, err := IsDirOrSymlinkToDir(dirPath, f) isDir, err := isDirOrSymlinkToDir(dirPath, f)
// Skip invalid symlinks // Skip invalid symlinks
if err != nil { if err != nil {
continue continue
} }
if isDir && !IsDirIgnored(dirPath, f) { if isDir && !isDirIgnored(dirPath, f) {
children = append(children, filepath.Join(dirPath, f.Name())) children = append(children, filepath.Join(dirPath, f.Name()))
} else { } else {
if f.ModTime().After(lastUpdated) { if f.ModTime().After(lastUpdated) {
@ -78,12 +78,12 @@ func (s *ChangeDetector) loadDir(dirPath string) (children []string, lastUpdated
return 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 // 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 // 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. // sending a request to the operating system to follow the symbolic link.
// Copied from github.com/karrick/godirwalk // 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() { if dirent.IsDir() {
return true, nil return true, nil
} }
@ -98,7 +98,7 @@ func IsDirOrSymlinkToDir(baseDir string, dirent os.FileInfo) (bool, error) {
return dirent.IsDir(), nil 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)) _, err := os.Stat(filepath.Join(baseDir, dirent.Name(), consts.SkipScanFile))
return err == nil return err == nil
} }

View File

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