Fix issue #267 - Reclone broken on windows #339
Closed
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.
Hopefully closes #267
While I wanted to stick to fixing the issue at hand, it became apparent that the issue was with the mutex guards. While this issue could also occur on Linux, it was more unlikely due to the logical difference in their kernels on object handling. So the way we handled the Repository mutex was problematic.
What I hoped to achieve for full atomicity and cross-platform support is making sure all file handles are dropped regardless, and keeping hold of the mutex guard throughout the whole reclone process. It was quite difficult to think about how to do in this situation. I've had @TheKrol test the code and it worked for him so here's the breakdown:
drop(replace(&mut *lock, dummy));
- takes the old repo out of the mutex, puts dummy in it's place, returns it, then drops it from the mutex, will keep the mutex guard itself in tact so we keep hold of the thread while releasing all handles to the old repo we want to replaceI wanted to make sure we kept hold of the mutex guard the whole time, as to achieve atomicity.
I'm still unsure if this is a good approach but it made sense to me, since the
Repository
struct isn't using tokio so we can't necessarily hold other threads while we work on it.