Skip to content

Commit b3af22f

Browse files
authored
Ignore missing files when counting used space (home-assistant#6174)
1 parent bbb9469 commit b3af22f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

supervisor/hardware/disk.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,16 @@ def get_dir_structure_sizes(self, path: Path, max_depth: int = 1) -> dict[str, A
9999
root_device = path.stat().st_dev
100100

101101
for child in path.iterdir():
102-
if not child.is_dir():
103-
size += child.stat(follow_symlinks=False).st_size
104-
continue
105-
106102
# Skip symlinks to avoid infinite loops
107103
if child.is_symlink():
108104
continue
109105

110106
try:
111-
# Skip if not on same device (external mount)
112-
if child.stat().st_dev != root_device:
113-
continue
107+
stat = child.stat(follow_symlinks=False)
108+
except FileNotFoundError:
109+
# File might disappear between listing and stat, ignore
110+
_LOGGER.warning("File not found: %s", child.as_posix())
111+
continue
114112
except OSError as err:
115113
if err.errno == errno.EBADMSG:
116114
self.sys_resolution.add_unhealthy_reason(
@@ -119,6 +117,13 @@ def get_dir_structure_sizes(self, path: Path, max_depth: int = 1) -> dict[str, A
119117
break
120118
continue
121119

120+
if stat.st_dev != root_device:
121+
continue
122+
123+
if not child.is_dir():
124+
size += stat.st_size
125+
continue
126+
122127
child_result = self.get_dir_structure_sizes(child, max_depth - 1)
123128
if child_result["used_bytes"] > 0:
124129
size += child_result["used_bytes"]

0 commit comments

Comments
 (0)