Fix "unable to rename file" Windows error (closes #56)
authorRicardo Garcia <sarbalap+freshmeat@gmail.com>
Wed, 12 Jan 2011 19:21:43 +0000 (20:21 +0100)
committerRicardo Garcia <sarbalap+freshmeat@gmail.com>
Wed, 12 Jan 2011 19:21:43 +0000 (20:21 +0100)
youtube-dl

index 13d42765b08c7338cc6ae405895513d3e751623f..c49c1b06448304f68d37395c7f6b23041d15b14f 100755 (executable)
@@ -429,6 +429,11 @@ class FileDownloader(object):
                        return filename
                return filename + u'.part'
 
+       def undo_temp_name(self, filename):
+               if filename.endswith(u'.part'):
+                       return filename[:-len(u'.part')]
+               return filename
+
        def try_rename(self, old_filename, new_filename):
                try:
                        if old_filename == new_filename:
@@ -698,6 +703,7 @@ class FileDownloader(object):
                        if stream is None:
                                try:
                                        (stream, tmpfilename) = sanitize_open(tmpfilename, open_mode)
+                                       filename = self.undo_temp_name(tmpfilename)
                                        self.report_destination(filename)
                                except (OSError, IOError), err:
                                        self.trouble(u'ERROR: unable to open for writing: %s' % str(err))