mod_image_for_recovery: change return trap to EXIT

copy_stateful() sets a RETURN trap that deletes a folder. Then there
are 2 calls of safe_umount function on two different mountpoints.

In bash 4.3 the RETURN trap doesn’t get executed, when those
functions return, so the trap executes after copy_stateful exits.
In bash 4.4 the trap does get executed when each of them gets
executed. As a result, the second attempt to remove said folder
fails, and the script stops execution.

This CL changes trap type to EXIT and directly deletes the folder at
the end of the function to ensure that we still does clean up on
error and on successful execution, and do not delete the folder
prematurely.

BUG=chromium:1180660
TEST=ran script manually, `cros tryjob -g '2713386 2713867 2713564 2717166'  arkham-release-tryjob`

Change-Id: I0860122bb81bd128bc63ae89f330b3044d06175a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2717166
Tested-by: Sergey Frolov <sfrolov@google.com>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Nicholas Verne <nverne@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
2 files changed