Improve temporary filename handling of special cases
This commit is contained in:
parent
d157d2597a
commit
7d950ca1d6
1 changed files with 5 additions and 1 deletions
|
@ -238,7 +238,9 @@ class FileDownloader(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def temp_name(filename):
|
def temp_name(filename):
|
||||||
"""Returns a temporary filename for the given filename."""
|
"""Returns a temporary filename for the given filename."""
|
||||||
return filename + '.part'
|
if filename == u'-' or (os.path.exists(filename) and not os.path.isfile(filename)):
|
||||||
|
return filename
|
||||||
|
return filename + u'.part'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_bytes(bytes):
|
def format_bytes(bytes):
|
||||||
|
@ -361,6 +363,8 @@ class FileDownloader(object):
|
||||||
|
|
||||||
def try_rename(self, old_filename, new_filename):
|
def try_rename(self, old_filename, new_filename):
|
||||||
try:
|
try:
|
||||||
|
if old_filename == new_filename:
|
||||||
|
return
|
||||||
os.rename(old_filename, new_filename)
|
os.rename(old_filename, new_filename)
|
||||||
except (IOError, OSError), err:
|
except (IOError, OSError), err:
|
||||||
self.trouble(u'ERROR: unable to rename file')
|
self.trouble(u'ERROR: unable to rename file')
|
||||||
|
|
Loading…
Reference in a new issue