entropy.transceivers.urlFetcher: always close file objects on disk

when reusing urlFetcher class more than once, make sure we close
every opened local file
This commit is contained in:
Fabio Erculiani
2009-03-29 21:55:20 +02:00
parent a65f1a863f
commit 93600a6b34
+11
View File
@@ -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: