Windows - diff file handling improvements (#1031)

pull/1033/head
dgtlmoon 2 years ago committed by GitHub
parent 63095f70ea
commit 85897e0bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -816,9 +816,11 @@ def changedetection_app(config=None, datastore_o=None):
newest_file = history[dates[-1]]
# Read as binary and force decode as UTF-8
# Windows may fail decode in python if we just use 'r' mode (chardet decode exception)
try:
with open(newest_file, 'r') as f:
newest_version_file_contents = f.read()
with open(newest_file, 'rb') as f:
newest_version_file_contents = f.read().decode('utf-8')
except Exception as e:
newest_version_file_contents = "Unable to read {}.\n".format(newest_file)
@ -830,8 +832,8 @@ def changedetection_app(config=None, datastore_o=None):
previous_file = history[dates[-2]]
try:
with open(previous_file, 'r') as f:
previous_version_file_contents = f.read()
with open(previous_file, 'rb') as f:
previous_version_file_contents = f.read().decode('utf-8')
except Exception as e:
previous_version_file_contents = "Unable to read {}.\n".format(previous_file)

@ -151,28 +151,29 @@ class model(dict):
import uuid
import logging
output_path = "{}/{}".format(self.__datastore_path, self['uuid'])
output_path = os.path.join(self.__datastore_path, self['uuid'])
self.ensure_data_dir_exists()
snapshot_fname = os.path.join(output_path, str(uuid.uuid4()))
snapshot_fname = "{}/{}.stripped.txt".format(output_path, uuid.uuid4())
logging.debug("Saving history text {}".format(snapshot_fname))
# in /diff/ we are going to assume for now that it's UTF-8 when reading
with open(snapshot_fname, 'wb') as f:
f.write(contents)
f.close()
# Append to index
# @todo check last char was \n
index_fname = "{}/history.txt".format(output_path)
index_fname = os.path.join(output_path, "history.txt")
with open(index_fname, 'a') as f:
f.write("{},{}\n".format(timestamp, snapshot_fname))
f.close()
self.__newest_history_key = timestamp
self.__history_n+=1
self.__history_n += 1
#@todo bump static cache of the last timestamp so we dont need to examine the file to set a proper ''viewed'' status
# @todo bump static cache of the last timestamp so we dont need to examine the file to set a proper ''viewed'' status
return snapshot_fname
@property

Loading…
Cancel
Save