mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-10 09:07:58 +01:00
parent
61ee5aeb73
commit
1394646a0a
1 changed files with 8 additions and 1 deletions
|
@ -71,7 +71,7 @@ def preferredencoding():
|
|||
|
||||
|
||||
def write_json_file(obj, fn):
|
||||
""" Encode obj as JSON and write it to fn, atomically """
|
||||
""" Encode obj as JSON and write it to fn, atomically if possible """
|
||||
|
||||
fn = encodeFilename(fn)
|
||||
if sys.version_info < (3, 0) and sys.platform != 'win32':
|
||||
|
@ -108,6 +108,13 @@ def write_json_file(obj, fn):
|
|||
try:
|
||||
with tf:
|
||||
json.dump(obj, tf)
|
||||
if sys.platform == 'win32':
|
||||
# Need to remove existing file on Windows, else os.rename raises
|
||||
# WindowsError or FileExistsError.
|
||||
try:
|
||||
os.unlink(fn)
|
||||
except OSError:
|
||||
pass
|
||||
os.rename(tf.name, fn)
|
||||
except:
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue