Browse Source

PASS1-56: Use XFP in backups filename and don't save `backup_num` (#32)

PASS1-34
Corey Lakey 4 years ago
committed by GitHub
parent
commit
608c3af9d7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ports/stm32/boards/Passport/modules/export.py
  2. 8
      ports/stm32/boards/Passport/modules/schema_evolution.py
  3. 10
      ports/stm32/boards/Passport/modules/utils.py

12
ports/stm32/boards/Passport/modules/export.py

@ -484,8 +484,9 @@ async def write_complete_backup(words, auto_backup=False, is_first_backup=False)
body = render_backup_contents().encode()
backup_num = settings.get('backup_num', 1)
# print('backup_num={}'.format(backup_num))
backup_num = 1
xfp = xfp2str(settings.get('xfp')).lower()
# print('XFP: {}'.format(xfp))
gc.collect()
@ -520,7 +521,7 @@ async def write_complete_backup(words, auto_backup=False, is_first_backup=False)
# Make a unique filename
while True:
base_filename = 'passport-backup-{}.7z'.format(backup_num)
base_filename = '{}-backup-{}.7z'.format(xfp, backup_num)
fname = '{}/{}'.format(backups_path, base_filename)
# Ensure filename doesn't already exist
@ -529,7 +530,6 @@ async def write_complete_backup(words, auto_backup=False, is_first_backup=False)
# Ooops...that exists, so increment and try again
backup_num += 1
# print('backup_num={}'.format(backup_num))
# print('Saving to fname={}'.format(fname))
@ -558,10 +558,6 @@ async def write_complete_backup(words, auto_backup=False, is_first_backup=False)
else:
return
# Update backup counter
backup_num += 1
settings.set('backup_num', backup_num)
if not auto_backup:
await ux_show_story('Saved backup to\n\n{}\n\nin /backups folder.'.format(base_filename),
title='Success', left_btn='NEXT', center=True, center_vertically=True)

8
ports/stm32/boards/Passport/modules/schema_evolution.py

@ -29,6 +29,14 @@ async def handle_schema_evolutions(update_from_to):
from_version = to_version
continue
elif from_version == '1.0.6' and to_version == '1.0.7':
# Handle evolutions
# This no longer used, so clean it out
settings.remove('backup_num')
from_version = to_version
continue
# We only reach here if no more evolutions are possible.
# Remove the update indicator from the settings.
# NOTE: There is a race condition here, but these evolutions should be extremely fast, and ideally

10
ports/stm32/boards/Passport/modules/utils.py

@ -491,10 +491,14 @@ def ensure_folder_exists(path):
return
def file_exists(path):
import os
from stat import S_ISREG
try:
with open(fname, 'wb') as fd:
return True
except:
s = os.stat(path)
mode = s[0]
return S_ISREG(mode)
except OSError as e:
return False
def folder_exists(path):

Loading…
Cancel
Save