shallow-backup icon indicating copy to clipboard operation
shallow-backup copied to clipboard

Enable resolution of variables in config paths

Open oWretch opened this issue 2 years ago • 1 comments

I have a desire to sync my configuration between machines where my username is different on each. Currently, the config backup just uses the raw path provided in the configuration file and doesn't attempt to resolve any variables from within the path.

This PR updates the config backup process to resolve variables in the config path string, such as ~ and $HOME and thereby allow one config to be used across different machines.

The upshot of this change is it would be possible for someone to perform advanced backup and restore by setting environment variables to move files around between machines.

oWretch avatar Jan 02 '23 00:01 oWretch

Hey! Thanks for the PR :) This fix makes sense to me.

~~I think it makes sense to break os.path.expandvars(os.path.expanduser(config_path)) out into a utility function. There are likely more places in the codebase we'd like to use that function.~~ Once that change is made, this seems good to go.

EDIT

Turns out this code is already a util function:

https://github.com/alichtman/shallow-backup/blob/7d7cc3ace3d65cc8258bc24958fcad8d17557152/shallow_backup/utils.py?rgh-link-date=2023-01-24T10%3A37%3A35Z#L214-L223

Let's use expand_to_abs_path() here.

alichtman avatar Jan 24 '23 10:01 alichtman