hermit icon indicating copy to clipboard operation
hermit copied to clipboard

[activate.tmpl.sh] Gracefully handle when the bin dir disappears

Open sw-square opened this issue 9 months ago • 1 comments

This PR updates update_hermit_env to handle the case when the bin directory disappears:

Before every command, hermit's update_hermit_env function interacts with ${HERMIT_ENV}/bin a few times (eg checking to see if it was modified, executing the ${HERMIT_ENV}/bin/hermit function, etc.) However, if either of these are missing, it causes noisy errors:

hm🐚 /tmp/hm % mv bin bin2
usage: date [-jnRu] [-I[date|hours|minutes|seconds]] [-f input_fmt]                                                                            
            [-r filename|seconds] [-v[+|-]val[y|m|w|d|H|M|S]]
            [[[[mm]dd]HH]MM[[cc]yy][.SS] | new_date] [+output_fmt]
update_hermit_env:4: no such file or directory: /tmp/hm/bin/hermit
update_hermit_env:5: no such file or directory: /tmp/hm/bin/hermit
update_hermit_env:6: no such file or directory: /tmp/hm/bin/hermit
hm🐚 /tmp/hm %

While during normal usage, the bin directory shouldn't disappear, I've encountered it multiple times personally (eg swapping between different git branches, before and after hermit as added to the repo, or even just accidentally moving the bin dir.)

This PR fixes this by checking to see if ${HERMIT_ENV}/bin/hermit exists before running the rest of update_hermit_env; If it doesn't it calls deactivate-hermit to disable hermit. However, _hermit_deactivate (called by deactivate-hermit) also uses ${HERMIT_ENV}/bin/hermit as well. So this also had to be changed to default to the system-wide hermit if needed

sw-square avatar Mar 07 '25 20:03 sw-square

I think we talked about this in Slack, but would you mind adding an integration test for this to integration/integration_test.go?

alecthomas avatar Mar 28 '25 00:03 alecthomas