fusesoc
fusesoc copied to clipboard
clean_cache rmtree fails on windows when removing readonly files in .git
Hello,
I did set some cores to cachable = false in the provider section having them downloaded from git everytime. In fusesoc list-cores they are seen as outdated (as expected) and with a run command fusesoc tries to download them every time. The first time everything goes well, but once the core is exisiting in the cache, the rmtree function in clean_cache (provider.py) is failing due to readonly files in .git/objects/pack or .git/objects/(number)
Only a windows issue and could be address for example like this
I had some issues with the proposed method above, better for me was to change all the files to read/write before deleting them:
def clean_cache(self):
def _make_tree_writable(topdir):
# Ensure all files and directories under topdir are writable
# (and readable) by owner.
for d, _, files in os.walk(topdir):
os.chmod(d, os.stat(d).st_mode | stat.S_IWRITE | stat.S_IREAD)
for fname in files:
fpath = os.path.join(d, fname)
if os.path.isfile(fpath):
os.chmod(fpath, os.stat(fpath).st_mode | stat.S_IWRITE | stat.S_IREAD)
if os.path.exists(self.files_root):
_make_tree_writable(self.files_root)
shutil.rmtree(self.files_root)
Sounds like a fair workaround. Do you want to send this as a PR? Perhaps just add a note that this is a Windows issue
Guess we can close this now