Fix test_restore_project PermissionError on Windows (#325)#343
Merged
Conversation
On Windows, TemporaryDirectory cleanup fails with WinError 32 when databases.db is transiently locked (e.g. by antivirus) immediately after being extracted from the tar backup. - Add _rmtree_robust() that retries shutil.rmtree up to 5 times with exponential backoff on Windows PermissionError - Restructure restore_project_directory so the temp dir is deleted as soon as shutil.copytree completes; metadata and switch logic move after cleanup, reducing the window during which files are held open - Fix unclosed file handle in _restore_project_metadata (open() → with)
On Python 3.14 Windows, SQLite connections from Database("foo").write({})
aren't closed promptly when switching projects. This means the file lock
on lci/databases.db persists when projects.delete_project(delete_dir=True)
calls shutil.rmtree, causing PermissionError [WinError 32].
The delete step was testing bw2data's delete_project, not restore
functionality. Since the restore target is "something-else" (a different
name), the delete isn't needed to test restore_project_directory.
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.
On Windows, TemporaryDirectory cleanup fails with WinError 32 when databases.db is transiently locked (e.g. by antivirus) immediately after being extracted from the tar backup.