Code in question can explain more than I can say in text I think. I've simplified it massively to keep it readable but in essence this is what I'm running.
def main():
with tempfile.TemporaryDirectory() as td:
for repo in repos:
subprocess.run("git clone --mirror {} {}".format(os.path.join(td, repo.path), repo.url)
The cloning part works just fine and goes through the entire list sucessfully. What doesn't is that when the "with ... as ..." exits it throws the following error(traceback starts at __exit__ of the context manager):
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\USERNAME\\AppData\\Local\\Temp\\tmp4ew2qffb\\sources\\REPONAME\\objects\\pack\\pack-abd0ff87083dbbcb90f707d8f2d53c730583bb6e.idx'
Running the script as admin doesn't help either. What is going wrong here?
EDIT: I've dug into it and it turns out python 3.7 the TemporaryDirectory cleanup does not support cleaning up read-only files on Windows.