From f86932df29aeaaadadfae3ec49d9f5bf94250bce Mon Sep 17 00:00:00 2001 From: Jaisen Mathai Date: Wed, 14 Oct 2015 23:40:40 -0700 Subject: [PATCH] Implement `touch` if hash db file does not exist --- elodie/localstorage.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/elodie/localstorage.py b/elodie/localstorage.py index 3786b9f..3ca8375 100644 --- a/elodie/localstorage.py +++ b/elodie/localstorage.py @@ -10,9 +10,16 @@ class Db(object): if not os.path.exists(constants.application_directory): os.makedirs(constants.application_directory) + # If the hash db doesn't exist we create it. + # Otherwise we only open for reading + if not os.path.isfile(constants.hash_db): + with open(constants.hash_db, 'a'): + os.utime(constants.hash_db, None) + self.hash_db = {} - # we need to open in w incase the file doesn't exist - with open(constants.hash_db, 'rw') as f: + + # We know from above that this file exists so we open it for reading only. + with open(constants.hash_db, 'r') as f: try: self.hash_db = json.load(f) except ValueError: