diff options
author | Jaime Marquínez Ferrándiz <jaimeMF@users.noreply.github.com> | 2014-11-20 08:16:42 +0100 |
---|---|---|
committer | Jaime Marquínez Ferrándiz <jaimeMF@users.noreply.github.com> | 2014-11-20 08:16:42 +0100 |
commit | 3ba098a6a5cfba528b3931c38790b582494031f8 (patch) | |
tree | 5f58d06f15d31a8e7b522401a3ed1c30ca06c7e1 /youtube_dl | |
parent | 07e378fa18b1c6b8becd46f6cf2d476e29a70a59 (diff) | |
parent | 1394646a0a531f6b13a4af7b1e3eec9951a6f9fb (diff) |
Merge pull request #4247 from ivan/info-json
Fix #4246 and #4244 .info.json bugs
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/utils.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 94b496dd0..bfe88b40b 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -71,10 +71,10 @@ 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): + if sys.version_info < (3, 0) and sys.platform != 'win32': encoding = get_filesystem_encoding() # os.path.basename returns a bytes object, but NamedTemporaryFile # will fail if the filename contains non ascii characters unless we @@ -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: |