Support restoring cache to a different home directory
Closed this issue · 4 comments
Right now, even for files that are cached from inside a user's home directory, like ~/.stack
, absolute path is stored and the files are restored to the same absolute path. This can create problems when restoring to a machine running under a different user with a different home directory (typically Permission denied
).
Files cached from inside a home directory should be restored relative to the home directory, whatever it is on the new machine.
@koterpillar You could invoke cache-s3 save --relative-path .stack
from the home directory. This will save only the relative path. Relative paths will be restored with respect to the current working directory.
@wagdav thanks again for implementing that feature. @koterpillar See discussion about it in #11
OK, the report wasn't clear at first: I'm using cache-s3 with Stack, so I didn't supply any of the relative options explicitly. Should cache-s3 save stack
apply the relative paths by default?
I think I see what you mean now. In your case the appropriate work around for the issue is by not using save stack
and instead manually saving it with:
$ cd ~
$ cache-s3 save --relative-path .stack
and similarly restoring it.
Now speaking about the feature, and correct me if I am wrong, you are suggesting:
- Prior to caching files get the home directory by doing
getHomeDirectory
- For all files being caches, see if a file path is prefixed with a home directory and if it is save it as relative
- Whenever restoring files do the opposite, see if a file is cached with a relative path and automatically restore it into the new home directory.
The problem is with restore process, since it would conflict with the current ability to save/restore relative paths. Also I'd be really opposed doing some heuristics around such a global setting as home directory.
One idea I'd likely be willing to accept is to have a cli flag --all-relative-paths
, which would simply error out if any of the files being cached are not relative to the current directory. Restoring would come natural, namely restore in the current directory. This approach would not conflict with current implementation and would work for save stack
and save stack work
commands, obviously with some cd
ing around.
@koterpillar if you feel like the above approach is one that could work for you, feel free to reopen the issue. That being said, I am unlikely to be doing much work on this in the near future, but I'll be happy to accept a PR.