From ae7ed73ec739d6cae8b837b988067a7aaae95e71 Mon Sep 17 00:00:00 2001 From: BJ Dweck Date: Fri, 10 Apr 2020 17:27:45 +0200 Subject: [PATCH] Avoid a situation in which the persistence layer creates the shards_file - but it is zero-length --- hermit/shards/shard_set.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hermit/shards/shard_set.py b/hermit/shards/shard_set.py index 66412c0..8a9c7c7 100644 --- a/hermit/shards/shard_set.py +++ b/hermit/shards/shard_set.py @@ -69,7 +69,7 @@ def _ensure_shards(self, shards_expected: bool = True) -> None: # If for some reason the persistence layer failed to create the # the shards file, we assume that we just need to initialize # it as an empty bson object. - if not os.path.exists(self.config.shards_file): + if not os.path.exists(self.config.shards_file) or os.stat(self.config.shards_file).st_size == 0: with open(self.config.shards_file, 'wb') as f: f.write(bson.dumps({}))