Package cache fails to delete on Windows due to .git folder
Describe the bug here.
Environment
- Windows 10
- 2.112.0
- Python 3.9
To Reproduce
- Use package cache on Windows and have a .git folder in your packages
- Let the cache localise it
- Let the cache try and delete it
Expected behavior Package should be deleted
Actual behavior rez fails to delete the package:
rez-pkg-cache 2023-05-19 11:46:21,059 PID-40548 WARNING Could not delete D:/local_packages_new\.sys\to_delete\pkg_a-1.0.0-e144a6d7bca1de358ace5c2aa19e1013: [WinError 5] Access is denied: '\\\\?\\D:\\local_packages_new\\.sys\\to_delete\\pkg_a-1.0.0-e144a6d7bca1de358ace5c2aa19e1013\\.git\\hooks'
rez-pkg-cache 2023-05-19 11:46:21,059 PID-40548 WARNING Could not delete D:/local_packages_new\.sys\to_delete\pkg_a-1.0.0-e144a6d7bca1de358ace5c2aa19e1013: [WinError 5] Access is denied: '\\\\?\\D:\\local_packages_new\\.sys\\to_delete\\pkg_a-1.0.0-e144a6d7bca1de358ace5c2aa19e1013\\.git\\hooks'
rez-pkg-cache 2023-05-19 11:46:21,059 PID-40548 WARNING Could not delete D:/local_packages_new\.sys\to_delete\pkg_a-1.1.0-c54644c778ef5949ff79b41465c974: [WinError 5] Access is denied: '\\\\?\\D:\\local_packages_new\\.sys\\to_delete\\pkg_a-1.1.0-c54644c778ef5949ff79b41465c974\\.git\\hooks'
rez-pkg-cache 2023-05-19 11:46:21,059 PID-40548 WARNING Could not delete D:/local_packages_new\.sys\to_delete\pkg_a-1.1.0-c54644c778ef5949ff79b41465c974: [WinError 5] Access is denied: '\\\\?\\D:\\local_packages_new\\.sys\\to_delete\\pkg_a-1.1.0-c54644c778ef5949ff79b41465c974\\.git\\hooks'
rez-pkg-cache 2023-05-19 11:46:21,059 PID-40548 WARNING Could not delete D:/local_packages_new\.sys\to_delete\pkg_b-2.5.3-1dafea82e87e74f8d2d7a543f2aa780: [WinError 5] Access is denied: '\\\\?\\D:\\local_packages_new\\.sys\\to_delete\\pkg_b-2.5.3-1dafea82e87e74f8d2d7a543f2aa780\\.git\\hooks'
A way to fix this:
In forceful_rmtree remove the if's on line 228 and 232 and it will be able to delete it properly.
I assume this has to do with the fact that Windows doesn't really use Unix permissions.
Is there any reason for these checks? Why not just force-change the permissions if it fails to delete?
Context: https://github.com/AcademySoftwareFoundation/rez/pull/959 and https://github.com/AcademySoftwareFoundation/rez/pull/1012
Thanks @JeanChristopheMorinPerso I've checked the PRs and it looks the os.access check came from the first time this function was added here without much explanation.
I suppose on Windows the check could just be bypassed so permissions always get changed.
@davidlatwe @instinct-vfx Any opinions on this?
FWIW we've been using rez without the os.access checks for a few days now and it's working without issues. No more errors in the logs and the local cache is getting cleaned properly.