Skip to content

Commit b794612

Browse files
authored
Merge pull request #36 from LandonTClipp/filemodes
Changing IsDir/IsFile/IsSymlink
2 parents ebdc800 + 19e796f commit b794612

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

path.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ func (p *Path) IsDir() (bool, error) {
211211
return afero.IsDir(p.Fs(), p.String())
212212
}
213213

214-
// IsDir returns whether or not the os.FileInfo object represents a
214+
// IsDir returns whether or not the os.FileMode object represents a
215215
// directory.
216-
func IsDir(fileInfo os.FileInfo) bool {
217-
return fileInfo.IsDir()
216+
func IsDir(mode os.FileMode) bool {
217+
return mode.IsDir()
218218
}
219219

220220
// IsEmpty checks if a given file or directory is empty.
@@ -484,13 +484,13 @@ func (p *Path) IsFile() (bool, error) {
484484
if err != nil {
485485
return false, err
486486
}
487-
return IsFile(fileInfo), nil
487+
return IsFile(fileInfo.Mode()), nil
488488
}
489489

490490
// IsFile returns whether or not the file described by the given
491-
// os.FileInfo is a regular file.
492-
func IsFile(fileInfo os.FileInfo) bool {
493-
return fileInfo.Mode().IsRegular()
491+
// os.FileMode is a regular file.
492+
func IsFile(mode os.FileMode) bool {
493+
return mode.IsRegular()
494494
}
495495

496496
// IsSymlink returns true if the given path is a symlink.
@@ -500,13 +500,13 @@ func (p *Path) IsSymlink() (bool, error) {
500500
if err != nil {
501501
return false, err
502502
}
503-
return IsSymlink(fileInfo), nil
503+
return IsSymlink(fileInfo.Mode()), nil
504504
}
505505

506506
// IsSymlink returns true if the file described by the given
507-
// os.FileInfo describes a symlink.
508-
func IsSymlink(fileInfo os.FileInfo) bool {
509-
return fileInfo.Mode()&os.ModeSymlink != 0
507+
// os.FileMode describes a symlink.
508+
func IsSymlink(mode os.FileMode) bool {
509+
return mode&os.ModeSymlink != 0
510510
}
511511

512512
// DeepEquals returns whether or not the path pointed to by other

walk.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (w *Walk) walkDFS(walkFn WalkFunc, root *Path, currentDepth int) error {
144144
if err := w.iterateImmediateChildren(root, func(child *Path, info os.FileInfo, encounteredErr error) error {
145145
// Since we are doing depth-first, we have to first recurse through all the directories,
146146
// and save all non-directory objects so we can defer handling at a later time.
147-
if IsDir(info) {
147+
if IsDir(info.Mode()) {
148148
if err := w.walkDFS(walkFn, child, currentDepth+1); err != nil {
149149
return err
150150
}
@@ -220,7 +220,7 @@ func (w *Walk) iterateImmediateChildren(root *Path, algorithmFunction WalkFunc)
220220
// the os.FileInfo passes all of the query specifications listed in
221221
// the walk options.
222222
func (w *Walk) passesQuerySpecification(info os.FileInfo) (bool, error) {
223-
if IsFile(info) {
223+
if IsFile(info.Mode()) {
224224
if !w.Opts.VisitFiles {
225225
return false, nil
226226
}
@@ -229,9 +229,9 @@ func (w *Walk) passesQuerySpecification(info os.FileInfo) (bool, error) {
229229
!w.Opts.MeetsMaximumSize(info.Size()) {
230230
return false, nil
231231
}
232-
} else if IsDir(info) && !w.Opts.VisitDirs {
232+
} else if IsDir(info.Mode()) && !w.Opts.VisitDirs {
233233
return false, nil
234-
} else if IsSymlink(info) && !w.Opts.VisitSymlinks {
234+
} else if IsSymlink(info.Mode()) && !w.Opts.VisitSymlinks {
235235
return false, nil
236236
}
237237

@@ -244,7 +244,7 @@ func (w *Walk) walkBasic(walkFn WalkFunc, root *Path, currentDepth int) error {
244244
}
245245

246246
err := w.iterateImmediateChildren(root, func(child *Path, info os.FileInfo, encounteredErr error) error {
247-
if IsDir(info) {
247+
if IsDir(info.Mode()) {
248248
if err := w.walkBasic(walkFn, child, currentDepth+1); err != nil {
249249
return err
250250
}

0 commit comments

Comments
 (0)