From 3c0d6e54c4929354106425636efac1f7f9abe06b Mon Sep 17 00:00:00 2001 From: Semi Malinen Date: Tue, 26 Jun 2018 08:07:38 +0300 Subject: [PATCH] Avoid data loss by postponing open() (#502) Postpone the reading of existing entries until a new entry has been obtained and is ready to be appended to the journal. This patch reduces the likelihood of losing entries when the user has launched concurrent jrnl sessions to add multiple entries. A proper solution would require locking the journal file for the time between reading and writing, but this is already good enough for typical interactive use cases. --- jrnl/Journal.py | 2 -- jrnl/cli.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 92a6774f..599e1ed5 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -36,8 +36,6 @@ class Journal(object): self.search_tags = None # Store tags we're highlighting self.name = name - self.open() - def __len__(self): """Returns the number of entries""" return len(self.entries) diff --git a/jrnl/cli.py b/jrnl/cli.py index 35764734..5751b041 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -216,6 +216,8 @@ def run(manual_args=None): else: mode_compose = False + journal.open() + # Writing mode if mode_compose: raw = " ".join(args.text).strip()