From 93600a6b340f9952eb9bafd6e029dc74c684d390 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 29 Mar 2009 21:55:20 +0200 Subject: [PATCH] entropy.transceivers.urlFetcher: always close file objects on disk when reusing urlFetcher class more than once, make sure we close every opened local file --- libraries/entropy/transceivers.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/entropy/transceivers.py b/libraries/entropy/transceivers.py index 933961efc..99c5eefa4 100644 --- a/libraries/entropy/transceivers.py +++ b/libraries/entropy/transceivers.py @@ -53,6 +53,7 @@ class urlFetcher: self.__disallow_redirect = disallow_redirect self.__speedlimit = speed_limit # kbytes/sec self.__existed_before = False + self.localfile = None # important to have this here too self.__datatransfer = 0 @@ -104,6 +105,16 @@ class urlFetcher: def __setup_resume_support(self): + # if client uses this instance more than + # once, make sure we close previously opened + # files. + if isinstance(self.localfile, file): + try: + self.localfile.flush() + self.localfile.close() + except (IOError, OSError,): + pass + # resume support if os.path.isfile(self.__path_to_save) and \ os.access(self.__path_to_save,os.W_OK) and self.__resume: