python-du 0.1.1__tar.gz → 0.1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-du
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A disk usage analyzer that prints a visual map of folder sizes
5
5
  Requires-Python: >=3.9
6
6
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "python-du"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "A disk usage analyzer that prints a visual map of folder sizes"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -21,6 +21,11 @@ class DirNode:
21
21
  return self.path.name or str(self.path)
22
22
 
23
23
 
24
+ def _allocated_size(stat_result: os.stat_result) -> int:
25
+ blocks = getattr(stat_result, "st_blocks", None)
26
+ return stat_result.st_size if blocks is None else blocks * 512
27
+
28
+
24
29
  def scan(root: Path, *, max_depth: int | None = None, follow_symlinks: bool = False) -> DirNode:
25
30
  """Walk *root* and return a tree of DirNode objects with computed sizes."""
26
31
  return _scan_dir(root.resolve(), depth=0, max_depth=max_depth, follow_symlinks=follow_symlinks)
@@ -51,7 +56,8 @@ def _scan_dir(
51
56
 
52
57
  if entry.is_file(follow_symlinks=follow_symlinks):
53
58
  try:
54
- node.own_size += entry.stat(follow_symlinks=follow_symlinks).st_size
59
+ stat_result = entry.stat(follow_symlinks=follow_symlinks)
60
+ node.own_size += _allocated_size(stat_result)
55
61
  node.file_count += 1
56
62
  except OSError:
57
63
  pass
@@ -83,7 +89,8 @@ def _shallow_size(path: Path) -> DirNode:
83
89
  for dirpath, _dirnames, filenames in os.walk(path):
84
90
  for fname in filenames:
85
91
  try:
86
- total += os.path.getsize(os.path.join(dirpath, fname))
92
+ stat_result = os.stat(os.path.join(dirpath, fname))
93
+ total += _allocated_size(stat_result)
87
94
  fcount += 1
88
95
  except OSError:
89
96
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-du
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A disk usage analyzer that prints a visual map of folder sizes
5
5
  Requires-Python: >=3.9
6
6
  Description-Content-Type: text/markdown
File without changes
File without changes
File without changes