Skip to content

Fix test_restore_project PermissionError on Windows (#325)#343

Merged
cmutel merged 2 commits into
mainfrom
worktree-enumerated-watching-thimble
Apr 16, 2026
Merged

Fix test_restore_project PermissionError on Windows (#325)#343
cmutel merged 2 commits into
mainfrom
worktree-enumerated-watching-thimble

Conversation

@cmutel

@cmutel cmutel commented Apr 16, 2026

Copy link
Copy Markdown
Member

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)

cmutel added 2 commits April 16, 2026 09:23
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.
@cmutel cmutel merged commit bcc9e27 into main Apr 16, 2026
36 checks passed
@cmutel cmutel mentioned this pull request Apr 16, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant