I believe the solution is as simple as just not performing those checks. We perform the check and immediately do the action, but instead we should just do the action which will fail if the check would've failed (and this avoids the race condition).
Instead of performing the check, match on the potential error of the actual operation. If it is "missing file" and should_fail_if_not_exists we propagate, otherwise we don't. Other errors always propagate.
With regards to:
https://github.com/expectocode/pagong/blob/a400492043ab3274f80dc162db811dacf45d42f6/src/fs_action.rs#L30-L32
I believe the solution is as simple as just not performing those checks. We perform the check and immediately do the action, but instead we should just do the action which will fail if the check would've failed (and this avoids the race condition).
As for
should_fail_if_not_exists
here:https://github.com/expectocode/pagong/blob/a400492043ab3274f80dc162db811dacf45d42f6/src/fs_action.rs#L47-L49
Instead of performing the check, match on the potential error of the actual operation. If it is "missing file" and
should_fail_if_not_exists
we propagate, otherwise we don't. Other errors always propagate.