mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-01-07 17:16:08 +00:00
Merge pull request #4247 from ivan/info-json
Fix #4246 and #4244 .info.json bugs
This commit is contained in:
commit
3ba098a6a5
|
@ -71,10 +71,10 @@ 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)
|
fn = encodeFilename(fn)
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0) and sys.platform != 'win32':
|
||||||
encoding = get_filesystem_encoding()
|
encoding = get_filesystem_encoding()
|
||||||
# os.path.basename returns a bytes object, but NamedTemporaryFile
|
# os.path.basename returns a bytes object, but NamedTemporaryFile
|
||||||
# will fail if the filename contains non ascii characters unless we
|
# will fail if the filename contains non ascii characters unless we
|
||||||
|
@ -108,6 +108,13 @@ def write_json_file(obj, fn):
|
||||||
try:
|
try:
|
||||||
with tf:
|
with tf:
|
||||||
json.dump(obj, 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)
|
os.rename(tf.name, fn)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue