diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-05-13 09:20:08 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-05-13 09:20:08 +0200 |
commit | f45c185fa9f7bab1714cbde1227c421e170c027a (patch) | |
tree | a545d3180c7e02e9c8cb561506673266122fe751 | |
parent | 1bd96c3a60e40d2490be834f95b9acca6c74eb07 (diff) |
Do not re-encode / to # if / is a platform separator, and correctly handle permission errors (Fixes #831)
-rw-r--r-- | youtube_dl/utils.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index f2342b10a..616948e10 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import errno import gzip import io import json @@ -334,12 +335,20 @@ def sanitize_open(filename, open_mode): stream = open(encodeFilename(filename), open_mode) return (stream, filename) except (IOError, OSError) as err: - # In case of error, try to remove win32 forbidden chars - filename = re.sub(u'[/<>:"\\|\\\\?\\*]', u'#', filename) + if err.errno in (errno.EACCES,): + raise - # An exception here should be caught in the caller - stream = open(encodeFilename(filename), open_mode) - return (stream, filename) + # In case of error, try to remove win32 forbidden chars + alt_filename = os.path.join( + 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): |