common: rename atomic_write_in_dir -> atomic_write (#36733)

rename
This commit is contained in:
Adeeb Shihadeh
2025-11-30 15:08:32 -08:00
committed by GitHub
parent ff755ed4bf
commit 7521fd11e2
4 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
import os
from uuid import uuid4
from openpilot.common.utils import atomic_write_in_dir
from openpilot.common.utils import atomic_write
class TestFileHelpers:
@@ -15,5 +15,5 @@ class TestFileHelpers:
assert f.read() == "test"
os.remove(path)
def test_atomic_write_in_dir(self):
self.run_atomic_write_func(atomic_write_in_dir)
def test_atomic_write(self):
self.run_atomic_write_func(atomic_write)
+1 -1
View File
@@ -32,7 +32,7 @@ class CallbackReader:
@contextlib.contextmanager
def atomic_write_in_dir(path: str, mode: str = 'w', buffering: int = -1, encoding: str | None = None, newline: str | None = None,
def atomic_write(path: str, mode: str = 'w', buffering: int = -1, encoding: str | None = None, newline: str | None = None,
overwrite: bool = False):
"""Write to a file atomically using a temporary file in the same directory as the destination file."""
dir_name = os.path.dirname(path)
+2 -2
View File
@@ -13,7 +13,7 @@ from cereal.messaging import SubMaster
from openpilot.system.hardware.hw import Paths
from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware import HARDWARE
from openpilot.common.utils import atomic_write_in_dir
from openpilot.common.utils import atomic_write
from openpilot.system.version import get_build_metadata
from openpilot.system.loggerd.config import STATS_DIR_FILE_LIMIT, STATS_SOCKET, STATS_FLUSH_TIME_S
@@ -167,7 +167,7 @@ def main() -> NoReturn:
if len(os.listdir(STATS_DIR)) < STATS_DIR_FILE_LIMIT:
if len(result) > 0:
stats_path = os.path.join(STATS_DIR, f"{boot_uid}_{idx}")
with atomic_write_in_dir(stats_path) as f:
with atomic_write(stats_path) as f:
f.write(result)
idx += 1
else:
+3 -3
View File
@@ -9,7 +9,7 @@ from urllib3.util import Timeout
from urllib3.exceptions import MaxRetryError
from openpilot.common.utils import atomic_write_in_dir
from openpilot.common.utils import atomic_write
from openpilot.system.hardware.hw import Paths
# Cache chunk size
@@ -88,7 +88,7 @@ class URLFile:
self._length = self.get_length_online()
if not self._force_download and self._length != -1:
with atomic_write_in_dir(file_length_path, mode="w", overwrite=True) as file_length:
with atomic_write(file_length_path, mode="w", overwrite=True) as file_length:
file_length.write(str(self._length))
return self._length
@@ -111,7 +111,7 @@ class URLFile:
# If we don't have a file, download it
if not os.path.exists(full_path):
data = self.read_aux(ll=CHUNK_SIZE)
with atomic_write_in_dir(full_path, mode="wb", overwrite=True) as new_cached_file:
with atomic_write(full_path, mode="wb", overwrite=True) as new_cached_file:
new_cached_file.write(data)
else:
with open(full_path, "rb") as cached_file: