FastOpp 0.4.7 - added fix for fastopp-startproject on Windows
Pre-releaseFix 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
-
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 /qcommand as fallback if Python methods fail - Handles both
PermissionErrorandOSErrorexceptions gracefully
-
Enhanced cleanup sequence:
- Added 1-second delay after Git operations on Windows to allow file handles to release
- Explicitly removes
.gitdirectory 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
-
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 /qcommand 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-startprojecton 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