Improve temporary filename handling of special cases
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>
Thu, 9 Dec 2010 18:33:04 +0000 (19:33 +0100)
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>
Thu, 9 Dec 2010 18:33:04 +0000 (19:33 +0100)
youtube-dl

index 415cf707379ca7bc667e0900372f9d7884f0675e..64c590fbfc30e954bde63cbde74d55af7997a308 100755 (executable)
@@ -238,7 +238,9 @@ class FileDownloader(object):
        @staticmethod
        def temp_name(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
        def format_bytes(bytes):
@@ -361,6 +363,8 @@ class FileDownloader(object):
        
        def try_rename(self, old_filename, new_filename):
                try:
+                       if old_filename == new_filename:
+                               return
                        os.rename(old_filename, new_filename)
                except (IOError, OSError), err:
                        self.trouble(u'ERROR: unable to rename file')