Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions prometheus_dirsize_exporter/exporter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import errno
import os
import time
import argparse
Expand Down Expand Up @@ -63,15 +64,23 @@ def get_dir_info(self, path: str) -> Optional[DirInfo]:
start_time = time.monotonic()
try:
self_statinfo = os.stat(path)

# Get absolute path of all children of directory
children = [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this was moved into the existing try rather than a new try added?

os.path.abspath(os.path.join(path, c))
for c in self.do_iops_action(os.listdir, path)
]
except FileNotFoundError:
# Directory was deleted from the time it was listed and now
return None

# Get absolute path of all children of directory
children = [
os.path.abspath(os.path.join(path, c))
for c in self.do_iops_action(os.listdir, path)
]
except OSError as e:
if e.errno == errno.EINVAL:
# See https://github.com/2i2c-org/prometheus-dirsize-exporter/issues/40
# A directory containing a unix domain socket accessed over NFS
# can raise EINVAL on listdir. Skip it rather than aborting.
return None
# Any other errors should just be propagated
raise
# Split into files and directories for different kinds of traversal.
# We count symlinks as files, but do not resolve them when checking size -
# but do include them in the mtime calculation.
Expand Down
Loading