Skip to content

Commit

Permalink
Move to be a package level function
Browse files Browse the repository at this point in the history
  • Loading branch information
euank committed Jan 18, 2017
1 parent b1ec030 commit a403efd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ func (self *RealFsInfo) GetDirDiskUsage(dir string, timeout time.Duration) (uint
}

func (self *RealFsInfo) GetDirInodeUsage(dir string, timeout time.Duration) (uint64, error) {
return GetDirInodeUsage(dir, timeout)
}

// GetDirInodeUsage determines the inodes used by a given directory. It avoid
// traversing onto other devices.
// If the directory does not exist or it is unable to access a file for some
// reason, it will return an error.
func GetDirInodeUsage(dir string, timeout time.Duration) (uint64, error) {
if dir == "" {
return 0, fmt.Errorf("invalid directory")
}
Expand All @@ -487,9 +495,6 @@ func (self *RealFsInfo) GetDirInodeUsage(dir string, timeout time.Duration) (uin
inodes := map[uint64]struct{}{}

err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if info.Mode() & os.ModeDevice {
return nil
}
if err != nil {
return fmt.Errorf("unable to count inodes for part of dir %s: %s", dir, err)
}
Expand Down

0 comments on commit a403efd

Please sign in to comment.