Dont fail if rc file dir doesnt exist

This commit is contained in:
Kovid Goyal
2021-08-18 10:06:06 +05:30
parent a993a71857
commit 2fcd57410a
+3 -1
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)