aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2025-12-30 19:47:52 +0100
committerDaniel Schadt <kingdread@gmx.de>2025-12-30 19:47:52 +0100
commit7dcb9b967a0aaadee0e23b85c363a035f6016684 (patch)
treedaa395f27330a4bc79753b43edaf206a8faeecfa
parentc4c76b6a758cd7c3979d6d109da5efcf384a3b40 (diff)
downloadfietsboek-7dcb9b967a0aaadee0e23b85c363a035f6016684.tar.gz
fietsboek-7dcb9b967a0aaadee0e23b85c363a035f6016684.tar.bz2
fietsboek-7dcb9b967a0aaadee0e23b85c363a035f6016684.zip
integrate JourneyDataManager with transactions
-rw-r--r--fietsboek/data.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/fietsboek/data.py b/fietsboek/data.py
index e288a03..1e97ada 100644
--- a/fietsboek/data.py
+++ b/fietsboek/data.py
@@ -382,9 +382,10 @@ class UserDataDir:
class JourneyDataDir:
"""Manager for a single journey's data."""
- def __init__(self, journey_id: int, path: Path):
+ def __init__(self, journey_id: int, path: Path, *, txn: Transaction | None = None):
self.journey_id = journey_id
self.path = path
+ self.txn = txn
def purge(self):
"""Purge all data pertaining to the journey.
@@ -392,8 +393,11 @@ class JourneyDataDir:
This function logs errors but raises no exception, as such it can
always be used to clean up after a track.
"""
- if self.path.is_dir():
- shutil.rmtree(self.path, ignore_errors=False, onerror=_log_deletion_error)
+ if self.txn:
+ self.txn.purge(self.path)
+ else:
+ if self.path.is_dir():
+ shutil.rmtree(self.path, ignore_errors=False, onerror=_log_deletion_error)
def preview_path(self) -> Path:
"""Gets the path to the "preview image".
@@ -407,11 +411,17 @@ class JourneyDataDir:
:param data: The data of the preview image.
"""
- self.preview_path().write_bytes(data)
+ if self.txn:
+ self.txn.write_bytes(self.preview_path(), data)
+ else:
+ self.preview_path().write_bytes(data)
def remove_preview(self):
"""Deletes the preview image."""
- self.preview_path().unlink()
+ if self.txn:
+ self.txn.unlink(self.preview_path())
+ else:
+ self.preview_path().unlink()
__all__ = ["generate_filename", "DataManager", "TrackDataDir", "UserDataDir", "JourneyDataDir"]