projects
/
youtube-dl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
61ee5ae
)
Fix "ERROR: Cannot write metadata to JSON file" on Windows
author
Ivan Kozik
<ivan@ludios.org>
Thu, 20 Nov 2014 06:05:39 +0000
(06:05 +0000)
committer
Ivan Kozik
<ivan@ludios.org>
Thu, 20 Nov 2014 06:26:34 +0000
(06:26 +0000)
Fixes #4246
youtube_dl/utils.py
patch
|
blob
|
history
diff --git
a/youtube_dl/utils.py
b/youtube_dl/utils.py
index f339fcb3134c3635cc265e03793fe7f544161c2a..bfe88b40bac05eea67d065953707c88549a190b6 100644
(file)
--- a/
youtube_dl/utils.py
+++ b/
youtube_dl/utils.py
@@
-71,7
+71,7
@@
def preferredencoding():
def write_json_file(obj, fn):
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':
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)
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:
os.rename(tf.name, fn)
except:
try: