Dont fail if rc file dir doesnt exist

This commit is contained in:
Kovid Goyal 2021-07-16 11:23:24 +05:30
parent a993a71857
commit 2fcd57410a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -22,7 +22,9 @@ posix_template = '''
def atomic_write(path: str, data: Union[str, bytes]) -> None:
mode = 'w' + ('b' if isinstance(data, bytes) else '')
fd, tpath = mkstemp(dir=os.path.dirname(path), text=isinstance(data, str))
base = os.path.dirname(path)
os.makedirs(base, exist_ok=True)
fd, tpath = mkstemp(dir=base, text=isinstance(data, str))
with open(fd, mode) as f:
shutil.copystat(path, tpath)
f.write(data)