Solve hg "abandoned transaction" issue #2562
Merged
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.
When a
fetchMercurial
operation is launched, Nix starts cloning the specified repo by executing ahg clone
command and stores the repo in thecacheDir
.In case there is an interruption during the cloning process, hg is left with an "abandoned transaction" in the cached repo directory.
When re-fetching the repo again, Nix will find that this repo already exists in the
cacheDir
and so it will execute ahg pull
command this time. And since we are left with an "abandoned transaction", hg will throw an "abandoned transaction" error and thefetchMercurial
operation will fail.So now we catch that error and we run a
hg recover
to fix the issue and finally we pull again by runninghg pull
.The hg command always returns an 255 exit code when there is an error, any error, so we can't detect the "abandoned transaction" error accurately based only on hg exit code.
However, reading hg source code, it turned out that hg throws that error only if a certain file named "journal" doesn't exist. Thus, in order to detect this error accurately, i check whether that file exists or not and if it is the case i run the recovering commands.