Skip to content

Commit 73769b9

Browse files
committed
Remove all POSIX related suggestions
1 parent 86e3b7d commit 73769b9

File tree

1 file changed

+1
-27
lines changed

1 file changed

+1
-27
lines changed

plugwise_usb/helpers/cache.py

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@
66
from contextlib import suppress
77
import logging
88
from os import (
9-
O_RDONLY as os_O_RDONLY,
10-
close as os_close,
11-
fsync as os_fsync,
129
getenv as os_getenv,
1310
getpid as os_getpid,
1411
name as os_name,
15-
open as os_open,
1612
)
1713
from os.path import expanduser as os_path_expand_user, join as os_path_join
1814
from pathlib import Path
@@ -30,15 +26,6 @@
3026
_LOGGER = logging.getLogger(__name__)
3127

3228

33-
def _fsync_parent_dir(path: Path) -> None:
34-
"""Ensure persistence on POSIX."""
35-
fd = os_open(str(path), os_O_RDONLY)
36-
try:
37-
os_fsync(fd)
38-
finally:
39-
os_close(fd)
40-
41-
4229
class PlugwiseCache:
4330
"""Base class to cache plugwise information."""
4431

@@ -144,25 +131,12 @@ async def write_cache(self, data: dict[str, str], rewrite: bool = False) -> None
144131
newline="\n",
145132
) as temp_file:
146133
await temp_file.writelines(data_to_write)
134+
# Ensure buffered data is written
147135
await temp_file.flush()
148-
# Ensure data reaches disk before rename
149-
with suppress(OSError, TypeError, AttributeError):
150-
# If fsync fails due to fileno() issues or other problems,
151-
# continue without it. Flush() provides reasonable durability.
152-
loop = get_running_loop()
153-
await loop.run_in_executor(None, os_fsync, temp_file.fileno())
154136

155137
# Atomic rename (overwrites atomically on all platforms)
156138
temp_path.replace(cache_file_path)
157139
temp_path = None # Successfully renamed
158-
if os_name != "nt":
159-
# Ensure directory entry is persisted on POSIX
160-
with suppress(OSError, PermissionError):
161-
# Directory fsync may fail on some filesystems
162-
# The atomic replace is still complete
163-
await loop.run_in_executor(
164-
None, _fsync_parent_dir, cache_file_path.parent
165-
)
166140

167141
if not self._cache_file_exists:
168142
self._cache_file_exists = True

0 commit comments

Comments
 (0)