diff --git a/server/src/uds/core/util/AutoAttributes.py b/server/src/uds/core/util/AutoAttributes.py index 7e759db0b..af9deaf6b 100644 --- a/server/src/uds/core/util/AutoAttributes.py +++ b/server/src/uds/core/util/AutoAttributes.py @@ -96,9 +96,9 @@ class AutoAttributes(Serializable): return # We keep original data (maybe incomplete) try: - data = encoders.decode_bz2(data) + data = encoders.decode(data, 'bzip2') except Exception: # With old zip encoding - data = encoders.decode_zip(data) + data = encoders.decode(data, 'zip') for pair in data.split('\2'): k, v = pair.split('\1') self.dict[k] = pickle.loads(str(v)) diff --git a/server/src/uds/core/util/FileStorage.py b/server/src/uds/core/util/FileStorage.py index 38f3633da..5658f6bb2 100644 --- a/server/src/uds/core/util/FileStorage.py +++ b/server/src/uds/core/util/FileStorage.py @@ -50,6 +50,7 @@ logger = logging.getLogger(__name__) class FileStorage(Storage): + def __init__(self, *args, **kwargs): self._base_url = getattr(settings, 'FILE_STORAGE', '/files') if self._base_url[-1] != '/': @@ -60,6 +61,7 @@ class FileStorage(Storage): try: cache = caches[cacheName] except: + logger.info('No cache for FileStorage configured.') cache = None self.cache = cache @@ -73,7 +75,6 @@ class FileStorage(Storage): Storage.__init__(self, *args, **kwargs) - def get_valid_name(self, name): return name.replace('\\', os.path.sep) @@ -119,7 +120,6 @@ class FileStorage(Storage): return self.cache.delete(self._getKey(name)) - def _open(self, name, mode='rb'): f = six.BytesIO(self._dbFileForReadOnly(name).data) f.name = name @@ -173,7 +173,9 @@ class FileStorage(Storage): except DBFile.DoesNotExist: return None + class CompressorFileStorage(FileStorage): + def __init__(self, *args, **kwargs): FileStorage.__init__(self, *args, **dict(kwargs, owner='compressor')) diff --git a/server/src/uds/core/util/encoders.py b/server/src/uds/core/util/encoders.py index 391efea49..e6ebe8f5a 100644 --- a/server/src/uds/core/util/encoders.py +++ b/server/src/uds/core/util/encoders.py @@ -41,14 +41,14 @@ def __toBinary(data): return data -def encode(data, encoder, asText): +def encode(data, encoder, asText=False): res = codecs.encode(__toBinary(data), encoder) if asText: return res.decode('utf8') return res -def decode(data, encoder, asText): +def decode(data, encoder, asText=False): res = codecs.decode(__toBinary(data), encoder) if asText: return res.decode('utf8') diff --git a/server/src/uds/models/DBFile.py b/server/src/uds/models/DBFile.py index 4732ea021..e0df84750 100644 --- a/server/src/uds/models/DBFile.py +++ b/server/src/uds/models/DBFile.py @@ -58,7 +58,16 @@ class DBFile(UUIDModel): @property def data(self): - return encoders.decode(encoders.decode(self.content, 'base64'), 'zip') + try: + return encoders.decode(encoders.decode(self.content, 'base64'), 'zip') + except Exception: + logger.error('DBFile {} has errors and cannot be used'.format(self.name)) + try: + self.delete() # Autodelete, invalid... + except: + logger.error('Could not even delete {}!!'.format(self.name)) + + return '' @data.setter def data(self, value):