aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fietsboek/fstrans.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/fietsboek/fstrans.py b/fietsboek/fstrans.py
index 13b0018..35cc992 100644
--- a/fietsboek/fstrans.py
+++ b/fietsboek/fstrans.py
@@ -68,7 +68,7 @@ import shutil
import uuid
from pathlib import Path
-import transaction
+import transaction # type: ignore
from filelock import FileLock
LOGGER = logging.getLogger(__name__)
@@ -128,7 +128,7 @@ class WriteBytes(Action):
def __init__(self, path: Path, data: bytes):
self.path = path
self.data = data
- self.old = None
+ self.old: bytes | None = None
def __repr__(self):
return f"<WriteBytes {len(self.data)} to {self.path}>"
@@ -152,7 +152,7 @@ class Unlink(Action):
def __init__(self, path: Path):
self.path = path
- self.old = None
+ self.old: bytes | None = None
def __repr__(self):
return f"<Unlink {self.path}>"
@@ -162,7 +162,10 @@ class Unlink(Action):
self.path.unlink()
def undo(self):
- self.path.write_bytes(self.old)
+ # This should not happen, unless an exception occurs when we read the
+ # file
+ if self.old is not None:
+ self.path.write_bytes(self.old)
class MakeDir(Action):
@@ -171,7 +174,7 @@ class MakeDir(Action):
def __init__(self, path: Path, exist_ok: bool = False):
self.path = path
self.exist_ok = exist_ok
- self.existed = None
+ self.existed: bool | None = None
def __repr__(self):
return f"<MakeDir {self.path}>"