mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-24 23:26:25 +00:00
Do not re-encode / to # if / is a platform separator, and correctly handle permission errors (Fixes #831)
This commit is contained in:
parent
1bd96c3a60
commit
f45c185fa9
@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import errno
|
||||||
import gzip
|
import gzip
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
@ -334,12 +335,20 @@ def sanitize_open(filename, open_mode):
|
|||||||
stream = open(encodeFilename(filename), open_mode)
|
stream = open(encodeFilename(filename), open_mode)
|
||||||
return (stream, filename)
|
return (stream, filename)
|
||||||
except (IOError, OSError) as err:
|
except (IOError, OSError) as err:
|
||||||
# In case of error, try to remove win32 forbidden chars
|
if err.errno in (errno.EACCES,):
|
||||||
filename = re.sub(u'[/<>:"\\|\\\\?\\*]', u'#', filename)
|
raise
|
||||||
|
|
||||||
# An exception here should be caught in the caller
|
# In case of error, try to remove win32 forbidden chars
|
||||||
stream = open(encodeFilename(filename), open_mode)
|
alt_filename = os.path.join(
|
||||||
return (stream, filename)
|
re.sub(u'[/<>:"\\|\\\\?\\*]', u'#', path_part)
|
||||||
|
for path_part in os.path.split(filename)
|
||||||
|
)
|
||||||
|
if alt_filename == filename:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
# An exception here should be caught in the caller
|
||||||
|
stream = open(encodeFilename(filename), open_mode)
|
||||||
|
return (stream, alt_filename)
|
||||||
|
|
||||||
|
|
||||||
def timeconvert(timestr):
|
def timeconvert(timestr):
|
||||||
|
Loading…
Reference in New Issue
Block a user