You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff --git a/dutree/dutree.py b/dutree/dutree.py
index 5f8a732..dbd3294 100755
--- a/dutree/dutree.py+++ b/dutree/dutree.py@@ -303,6 +303,20 @@ class DuNode:
class DuScan:
"Disk Usage Tree scanner"
+ class EmulateUnixStatResult:+ """On some Unix systems (such as Linux), the following+ attributes may also be available:+ - st_blocks+ ...++ Windows does not have it. Wrap the stat_result in a+ EmulateUnixStatResult and pretend we have st_blocks.+ """+ def __init__(self, st):+ self.st_blocks = (st.st_size + 511) >> 9+ self.st_mode = st.st_mode+ self.st_size = st.st_size+
def __init__(self, pathname):
self._path = self._normpath(pathname)
self._tree = None
@@ -390,6 +404,15 @@ class DuScan:
warnings.warn(str(e), OsWarning)
continue
+ try:+ st.st_blocks+ except AttributeError:+ # In Python, using exceptions for the _uncommon_ case,+ # keeps the common (unix/linux) case (which has st_blocks)+ # fast.+ warnings.warn('No st_blocks on your OS, emulating', OsWarning)+ st = self.EmulateUnixStatResult(st)+
if S_ISREG(st.st_mode):
if st.st_blocks == 0:
# Pseudo-files, like the one in /proc have 0-block
Throws
AttributeError: 'os.stat_result' object has no attribute 'st_blocks'
instead
The text was updated successfully, but these errors were encountered: