Skip to content

FastOpp 0.4.7 - added fix for fastopp-startproject on Windows

Pre-release
Pre-release

Choose a tag to compare

@codetricity codetricity released this 03 Nov 23:59
· 13 commits to main since this release
baf7e9b

Fix Windows File Locking Issues in fastopp-startproject

Problem

The fastopp-startproject command was failing on Windows with a [WinError 5] Access is denied error when trying to remove the temporary Git repository directory. This occurred specifically when attempting to delete files in .git/objects/pack/, which are often locked by:

  • Git processes that haven't fully released file handles
  • Windows Defender or antivirus real-time scanning
  • Windows Search indexing services
  • Background processes accessing the directory

The error occurred at line 184 when shutil.rmtree(temp_dir) attempted to remove the temporary directory containing the cloned repository.

Solution

Implemented Windows-specific file locking handling with retry logic:

Key Changes

  1. Added remove_directory_with_retry() function:

    • Detects Windows OS automatically
    • Removes read-only file attributes before deletion attempts
    • Implements exponential backoff retry mechanism (up to 5 attempts)
    • Uses Windows native rmdir /s /q command as fallback if Python methods fail
    • Handles both PermissionError and OSError exceptions gracefully
  2. Enhanced cleanup sequence:

    • Added 1-second delay after Git operations on Windows to allow file handles to release
    • Explicitly removes .git directory from temp folder before removing entire temp directory
    • Replaced all shutil.rmtree() calls with the retry function for consistency
    • Provides helpful warnings if cleanup fails, instructing users to manually delete if needed
  3. Windows-specific optimizations:

    • Removes read-only attributes recursively before deletion
    • Longer initial wait time (1 second) on first retry for Windows
    • Multiple retry attempts with increasing delays

Technical Details

  • Files Modified: fastopp/__init__.py
  • Function Added: remove_directory_with_retry() (nested helper function)
  • Retry Logic: Exponential backoff with up to 5 attempts
  • Fallback: Windows rmdir /s /q command for stubborn directories

Testing

This fix should resolve the Windows error reported where the command failed with:

[WinError 5] Access is denied: 'fastopp-temp\.git\objects\pack\pack-31f60a45b3c2647d41fe49d3c32d79c637203795.idx'

The changes maintain backward compatibility with Unix/Linux/macOS systems and only activate Windows-specific behavior when running on Windows.

Impact

  • ✅ Fixes fastopp-startproject on Windows
  • ✅ No breaking changes - works on all platforms
  • ✅ More robust error handling for file operations
  • ✅ Better user experience with helpful error messages if cleanup fails