r.earthworks: use a temporary region to restore the user's region on exit#1743
Open
Valyrian-Code wants to merge 2 commits into
Open
r.earthworks: use a temporary region to restore the user's region on exit#1743Valyrian-Code wants to merge 2 commits into
Valyrian-Code wants to merge 2 commits into
Conversation
…exit The finally block in main() registers cleanup of temporary maps but does not restore the computational region, so on an error between the region change and the series() restore the user could be left with a changed region. Wrap the region handling in gs.use_temp_region() so the original region is restored automatically on exit, including on error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #1741. Same
use_temp_region()pattern as #1742 (r.soillossbare).In
main(), r.earthworks saves the current region assource, changes the region while modeling each quadrant, and restores it inseries(). On a normal run that works fine. But thefinallyblock only registers cleanup of the temporary maps, it does not restore the region, so on an error between the region change and theseries()restore the user can be left with a changed region (and the savedsourceregion gets removed by the cleanup too).Wrapping the region handling in
gs.use_temp_region()at the start ofmain()restores the user's original region automatically on exit, including on error. It is additive: the existingsourcesave/restore still drives the per-quadrant and cumulative extents.In practice
series()restores on the normal path, so this mainly hardens the error path. @baharmon, since this is your module, does this look reasonable to you? Happy to adjust.