fix hash
This commit is contained in:
parent
4c79d283b0
commit
9132520d01
@ -1,3 +1,3 @@
|
|||||||
SELECT name, path, size, m_date, c_date, crypt.id, compress_mode
|
SELECT name, path, size, m_date, c_date, crypt.id, compress_mode, sha1sum
|
||||||
FROM files
|
FROM files
|
||||||
INNER JOIN crypt ON files.crypt_id = crypt.id
|
INNER JOIN crypt ON files.crypt_id = crypt.id
|
14
backup.py
14
backup.py
@ -65,7 +65,7 @@ class Backup:
|
|||||||
if crypt_id is not None:
|
if crypt_id is not None:
|
||||||
print("Proceed", uri, ' ==> ', crypt_id)
|
print("Proceed", uri, ' ==> ', crypt_id)
|
||||||
enc = crypt(compress(uri), self.key)
|
enc = crypt(compress(uri), self.key)
|
||||||
self.bdd.set_crypt_attr(crypt_id, compress_mode="gz", sha1sum=hashlib.sha1(enc.read()).hexdigest())
|
self.bdd.set_crypt_attr(crypt_id, compress_mode="gz", sha1sum=get_hash(enc))
|
||||||
print(" Size : ", get_size(enc))
|
print(" Size : ", get_size(enc))
|
||||||
upload_file(enc, self.save_mode, file_name=os.path.join(self.save_location, str(crypt_id).zfill(ZFILL)), bucket=self.buk)
|
upload_file(enc, self.save_mode, file_name=os.path.join(self.save_location, str(crypt_id).zfill(ZFILL)), bucket=self.buk)
|
||||||
else:
|
else:
|
||||||
@ -82,7 +82,7 @@ class Backup:
|
|||||||
print("Proceed", path, ":", [file['name'] for file in files], ' ==> ', crypt_id)
|
print("Proceed", path, ":", [file['name'] for file in files], ' ==> ', crypt_id)
|
||||||
tarball = tar([file['path'] for file in files])
|
tarball = tar([file['path'] for file in files])
|
||||||
enc = crypt(compress(tarball), self.key)
|
enc = crypt(compress(tarball), self.key)
|
||||||
self.bdd.set_crypt_attr(crypt_id, compress_mode="tar.gz", sha1sum=hashlib.sha1(enc.read()).hexdigest())
|
self.bdd.set_crypt_attr(crypt_id, compress_mode="tar.gz", sha1sum=get_hash(enc))
|
||||||
print(" Size : ", get_size(enc))
|
print(" Size : ", get_size(enc))
|
||||||
upload_file(enc, self.save_mode, file_name=os.path.join(self.save_location, str(crypt_id).zfill(ZFILL)), bucket=self.buk)
|
upload_file(enc, self.save_mode, file_name=os.path.join(self.save_location, str(crypt_id).zfill(ZFILL)), bucket=self.buk)
|
||||||
|
|
||||||
@ -125,6 +125,16 @@ def get_size(in_file):
|
|||||||
return human_size(filesize, decimal_places=1, unit='si')
|
return human_size(filesize, decimal_places=1, unit='si')
|
||||||
|
|
||||||
|
|
||||||
|
def get_hash(infile):
|
||||||
|
if type(infile) is str:
|
||||||
|
file = open(infile, 'rb')
|
||||||
|
elif type(infile) is tempfile.SpooledTemporaryFile:
|
||||||
|
infile.seek(0)
|
||||||
|
file = infile
|
||||||
|
|
||||||
|
return hashlib.sha1(file.read()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def tar(files):
|
def tar(files):
|
||||||
tarball = tempfile.SpooledTemporaryFile()
|
tarball = tempfile.SpooledTemporaryFile()
|
||||||
with tarfile.open(fileobj=tarball, mode='w') as zipfile:
|
with tarfile.open(fileobj=tarball, mode='w') as zipfile:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user