perform filesystem R/W checks at startup#10177
perform filesystem R/W checks at startup#10177accumulator wants to merge 1 commit intospesmilo:masterfrom
Conversation
later when actual writes are performed (e.g. spesmilo#4151)
zrawsig
left a comment
There was a problem hiding this comment.
Suggested a refactor to improve the readability, small grammar nitpick and suggested to move the new function to the first half of the file to group all similar functions together and not mix with the classes.
| for f in ['config', 'blockchain_headers', 'recent_servers']: | ||
| fpath = os.path.join(electrum_path, f) | ||
| if os.path.exists(fpath): | ||
| if not os.access(fpath, os.R_OK | os.W_OK): |
There was a problem hiding this comment.
The os.access() check is repeated a few times with the exception message.
This could be factored out to improve readability, for example:
def check_permissions(path: str):
if not os.access(path, os.R_OK | os.W_OK):
raise Exception(f'Cannot read/write {path}')| def check_fs_permissions(config: 'SimpleConfig'): | ||
| electrum_path = config.electrum_path() | ||
| if not os.access(electrum_path, os.R_OK | os.W_OK): | ||
| raise Exception('can not read/write root folder at ' + electrum_path) |
There was a problem hiding this comment.
"can not" is grammatically incorrect, please change to "Cannot". See the factored out example above.
| util.trigger_callback('recently_opened_wallets_update') | ||
|
|
||
|
|
||
| def check_fs_permissions(config: 'SimpleConfig'): |
There was a problem hiding this comment.
This is the only function below the classes, while other generic functions such as this one lives in the beginning of the file. Maybe it could be moved there to keep the file organized that way.
perform filesystem R/W checks at startup. This avoids raising Exceptions later when actual writes are performed (e.g. #4151).
Not sure yet how portable this is, needs testing on win and mac