verify checksum
This commit is contained in:
parent
ead909e2ca
commit
1cc0e98de3
19
backup.py
19
backup.py
@ -92,10 +92,16 @@ class Backup:
|
||||
for file in files:
|
||||
if file['crypt_id'] is not None:
|
||||
encrypted_file = download_file(self.save_mode, os.path.join(self.save_location, str(file['crypt_id']).zfill(ZFILL)), bucket=self.buk)
|
||||
|
||||
if parents:
|
||||
save_path = os.path.join(save_path, file['path'])
|
||||
uncompress(uncrypt(encrypted_file, self.key), file['name'], save_path, file['compress_mode'])
|
||||
file_hash = get_hash(encrypted_file)
|
||||
if file['sha1sum'] == file_hash:
|
||||
if parents:
|
||||
save_path = os.path.join(save_path, file['path'])
|
||||
uncompress(uncrypt(encrypted_file, self.key), file['name'], save_path, file['compress_mode'])
|
||||
else:
|
||||
print("Checksum don't match:")
|
||||
print("{} {}".format(file['sha1sum'], "BDD"))
|
||||
print("{} {}".format(file_hash, "File"))
|
||||
print()
|
||||
|
||||
|
||||
def upload_file(file, mode, file_name, bucket=None):
|
||||
@ -265,7 +271,7 @@ class DataBase:
|
||||
# for path in [file['path'] for file in list_file]:
|
||||
for path in list_file:
|
||||
path = pathlib.PureWindowsPath(path).as_posix()
|
||||
cursor.execute("""SELECT crypt_id, compress_mode FROM files
|
||||
cursor.execute("""SELECT crypt_id, compress_mode, sha1sum FROM files
|
||||
INNER JOIN crypt ON files.crypt_id = crypt.id
|
||||
WHERE path=?""", (path,))
|
||||
retval = cursor.fetchone()
|
||||
@ -273,7 +279,8 @@ class DataBase:
|
||||
crypt_list.append({'name': os.path.basename(path),
|
||||
'path': path,
|
||||
'crypt_id': retval['crypt_id'],
|
||||
'compress_mode': retval['compress_mode']})
|
||||
'compress_mode': retval['compress_mode'],
|
||||
'sha1sum': retval['sha1sum']})
|
||||
except TypeError:
|
||||
crypt_list.append({'path': path, 'crypt': None})
|
||||
return crypt_list
|
||||
|
Loading…
x
Reference in New Issue
Block a user