Crash fix: Data store sub-directories werent always being created when needed

be-sure-dirs-exist
dgtlmoon 2 years ago
parent 9bff1582f7
commit 371e31961e

@ -83,6 +83,12 @@ class model(dict):
return False return False
def ensure_data_dir_exists(self):
target_path = os.path.join(self.__datastore_path, self['uuid'])
if not os.path.isdir(target_path):
print ("> Creating data dir {}".format(target_path))
os.mkdir(target_path)
@property @property
def label(self): def label(self):
# Used for sorting # Used for sorting
@ -149,9 +155,7 @@ class model(dict):
output_path = "{}/{}".format(self.__datastore_path, self['uuid']) output_path = "{}/{}".format(self.__datastore_path, self['uuid'])
# Incase the operator deleted it, check and create. self.ensure_data_dir_exists()
if not os.path.isdir(output_path):
os.mkdir(output_path)
snapshot_fname = "{}/{}.stripped.txt".format(output_path, uuid.uuid4()) snapshot_fname = "{}/{}.stripped.txt".format(output_path, uuid.uuid4())
logging.debug("Saving history text {}".format(snapshot_fname)) logging.debug("Saving history text {}".format(snapshot_fname))

@ -8,7 +8,7 @@ import threading
import time import time
import uuid as uuid_builder import uuid as uuid_builder
from copy import deepcopy from copy import deepcopy
from os import mkdir, path, unlink from os import path, unlink
from threading import Lock from threading import Lock
import re import re
import requests import requests
@ -324,12 +324,7 @@ class ChangeDetectionStore:
new_watch.update(apply_extras) new_watch.update(apply_extras)
self.__data['watching'][new_uuid]=new_watch self.__data['watching'][new_uuid]=new_watch
# Get the directory ready self.__data['watching'][new_uuid].ensure_data_dir_exists()
output_path = "{}/{}".format(self.datastore_path, new_uuid)
try:
mkdir(output_path)
except FileExistsError:
print(output_path, "already exists.")
if write_to_disk_now: if write_to_disk_now:
self.sync_to_json() self.sync_to_json()
@ -352,6 +347,8 @@ class ChangeDetectionStore:
else: else:
target_path = os.path.join(self.datastore_path, watch_uuid, "last-screenshot.png") target_path = os.path.join(self.datastore_path, watch_uuid, "last-screenshot.png")
self.data['watching'][watch_uuid].ensure_data_dir_exists()
with open(target_path, 'wb') as f: with open(target_path, 'wb') as f:
f.write(screenshot) f.write(screenshot)
f.close() f.close()

Loading…
Cancel
Save