From 1b02cbb7e029fee73a19b3b3f03c034c8312dd87 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Tue, 17 Aug 2010 18:27:53 +0200 Subject: [PATCH] [entropy.transceivers] FTP plugin: fix temporary file handling in EntropyFtpUriHandler.download() --- .../plugins/interfaces/ftp_plugin.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py b/libraries/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py index 19ea1b7f4..be2ff58e0 100644 --- a/libraries/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py +++ b/libraries/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py @@ -367,6 +367,12 @@ class EntropyFtpUriHandler(EntropyUriHandler): rc = self.__ftpconn.retrbinary('RETR ' + path, writer, 8192) f.flush() + self._update_progress(force = True) + done = rc.find("226") != -1 + if done: + # download complete, atomic mv + os.rename(tmp_save_path, save_path) + except (IOError, self.ftplib.error_reply, socket.error) as e: # connection reset by peer @@ -387,16 +393,8 @@ class EntropyFtpUriHandler(EntropyUriHandler): continue finally: - try: + if os.path.isfile(tmp_save_path): os.remove(tmp_save_path) - except OSError: - pass - - self._update_progress(force = True) - done = rc.find("226") != -1 - if done: - # download complete, atomic mv - os.rename(tmp_save_path, save_path) return done