fusesoc icon indicating copy to clipboard operation
fusesoc copied to clipboard

clean_cache rmtree fails on windows when removing readonly files in .git

Open schwende opened this issue 2 years ago • 2 comments

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

schwende avatar Apr 04 '22 10:04 schwende

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)

schwende avatar Apr 14 '22 07:04 schwende

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

olofk avatar Apr 14 '22 08:04 olofk

Guess we can close this now

olofk avatar Oct 31 '22 22:10 olofk