From cd9cf8d66a3b10e8629733c85c8db4fb40a914e7 Mon Sep 17 00:00:00 2001 From: semi Date: Tue, 26 Jun 2018 21:27:52 +0300 Subject: [PATCH] Avoid data loss by postponing open() (#502) (#545) 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()