Added check for ismount() and empty directories.

Previously the free space of the underlying filesystem would be reported if the path provided was a directory but not a valid mountpoint. This adds a check to first confirm whether a directory is a mountpoint using os.path.ismount(), and if not, then runs an os.listdir() to count the files; empty directories are considered not mounted.

This functionality allows for usage on setups with NFS and will not report free space of underlying filesystem in cases with local mountpoints as path.
This commit is contained in:
Douglas Eddie 2015-11-24 22:51:01 +00:00 committed by enkore
parent 1c4f941304
commit 731749f0e3

View File

@ -37,10 +37,7 @@ class Disk(IntervalModule):
round_size = 2
mounted_only = False
def run(self):
try:
stat = os.statvfs(self.path)
except Exception:
def not_mounted(self):
if self.mounted_only:
self.output = {}
else:
@ -48,6 +45,17 @@ class Disk(IntervalModule):
"full_text": self.format_not_mounted,
"color": self.color_not_mounted,
}
def run(self):
if os.path.isdir(self.path) and not os.path.ismount(self.path):
if len(os.listdir(self.path)) == 0:
self.not_mounted()
return
try:
stat = os.statvfs(self.path)
except Exception:
self.not_mounted()
return
available = (stat.f_bsize * stat.f_bavail) / self.divisor