Make AtExit a stack and make DirectoryTemporary more robust #2856
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is kind of 2 PRs merged together, can split if required.
Firstly, the error message when cleaning up a DirectoryTemporary if it was already deleted wasn't useful, and other temporary directories wouldn't be deleted after the first failing one. This could easily occur if a temporary directory was made, then IO_fork was called.
Secondly, while debugging this I was having some problems which turned out to be caused by the fact the AtExit functions are run in-order. This is against how exit handlers normally work, as it means the first handlers GAP installs (which do things like flush buffers) get run before later, or user-installed handlers.
I pop the list of AtExit handlers, rather than just calling
Reverse
on the list, in case new handlers are installed as GAP is closing.