diff options
author | Stanislav <n.c.necros@gmail.com> | 2020-04-06 14:39:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 14:39:45 +0300 |
commit | 40dc08db749ef1f7dd3712ba1e629caa8fa6dada (patch) | |
tree | a030d6b97d0382826e4363564238f43b7dd5d4b6 /Tools | |
parent | 16f54d2d72d4f5297d17f58e8921bfc85cbc62cb (diff) |
small fix for empty "*index*" file
some index file don't contain 'vol' folder, only manifest. this fix check if 'vol' folder is exists
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/Commandline/ReEncrypt/ReEncrypt.py | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/Tools/Commandline/ReEncrypt/ReEncrypt.py b/Tools/Commandline/ReEncrypt/ReEncrypt.py index 96fbc575a..dabdc5d3a 100644 --- a/Tools/Commandline/ReEncrypt/ReEncrypt.py +++ b/Tools/Commandline/ReEncrypt/ReEncrypt.py @@ -59,36 +59,36 @@ def handleIndex(options, dindex_enc): unzip(temp_dindex,temp_path_zip) vol_path = os.path.join(temp_path_zip,'vol') - - for dblock in os.listdir(vol_path): - data = [] - with open(os.path.join(vol_path, dblock)) as data_file: - data = json.load(data_file, object_pairs_hook=OrderedDict) - - expected_hash = data['volumehash'].encode('utf8') - expected_volumesize = data['volumesize'] - - if (options['verify_hash']): - actual_hash = computeHash(os.path.join(options['orig']['path'],dblock)) - actual_volumesize=os.stat(os.path.join(options['orig']['path'],dblock)).st_size - print('dblock: %s expected_hash: %s calc_hash: %s exact: %s' % (dblock,expected_hash.decode('utf8'),actual_hash.decode('utf8'),expected_hash==actual_hash)) - - with NamedTemporaryFile() as temp_dblock: - dblock_enc_fullpath = os.path.join(options['orig']['path'],dblock) - dblock_reenc_fullpath = os.path.join(options['new']['path'],change_ext(dblock,options['orig']['extension'],options['new']['extension'])) - decrypt(options['orig'],dblock_enc_fullpath,options['orig']['passwd'],temp_dblock.name) - encrypt(options['new'],temp_dblock.name,options['new']['passwd'], dblock_reenc_fullpath) - new_hash = computeHash(dblock_reenc_fullpath) - - data['volumehash'] = new_hash.decode('utf8') - data['volumesize'] = os.stat(os.path.join(options['new']['path'],change_ext(dblock,options['orig']['extension'],options['new']['extension']))).st_size - print('dblock: %s old_hash: %s new_hash: %s' % (dblock,expected_hash.decode('utf8'),data['volumehash'])) - - with open(os.path.join(vol_path,dblock),'w') as data_file: - json.dump(data, data_file) - - os.rename(os.path.join(vol_path, dblock), os.path.join(vol_path, change_ext(dblock,options['orig']['extension'],options['new']['extension']))) - + if os.path.exists(vol_path): + for dblock in os.listdir(vol_path): + data = [] + with open(os.path.join(vol_path, dblock)) as data_file: + data = json.load(data_file, object_pairs_hook=OrderedDict) + + expected_hash = data['volumehash'].encode('utf8') + expected_volumesize = data['volumesize'] + + if (options['verify_hash']): + actual_hash = computeHash(os.path.join(options['orig']['path'],dblock)) + actual_volumesize=os.stat(os.path.join(options['orig']['path'],dblock)).st_size + print('dblock: %s expected_hash: %s calc_hash: %s exact: %s' % (dblock,expected_hash.decode('utf8'),actual_hash.decode('utf8'),expected_hash==actual_hash)) + + with NamedTemporaryFile() as temp_dblock: + dblock_enc_fullpath = os.path.join(options['orig']['path'],dblock) + dblock_reenc_fullpath = os.path.join(options['new']['path'],change_ext(dblock,options['orig']['extension'],options['new']['extension'])) + decrypt(options['orig'],dblock_enc_fullpath,options['orig']['passwd'],temp_dblock.name) + encrypt(options['new'],temp_dblock.name,options['new']['passwd'], dblock_reenc_fullpath) + new_hash = computeHash(dblock_reenc_fullpath) + + data['volumehash'] = new_hash.decode('utf8') + data['volumesize'] = os.stat(os.path.join(options['new']['path'],change_ext(dblock,options['orig']['extension'],options['new']['extension']))).st_size + print('dblock: %s old_hash: %s new_hash: %s' % (dblock,expected_hash.decode('utf8'),data['volumehash'])) + + with open(os.path.join(vol_path,dblock),'w') as data_file: + json.dump(data, data_file) + + os.rename(os.path.join(vol_path, dblock), os.path.join(vol_path, change_ext(dblock,options['orig']['extension'],options['new']['extension']))) + make_zipfile(temp_dindex_reenc.name,temp_path_zip) encrypt(options['new'],temp_dindex_reenc.name, options['new']['passwd'],dindex_reenc_fullpath) |