This fix to the MakeRequest() method gets rid of the hiddeous
authorMarc Fiuczynski <mef@cs.princeton.edu>
Fri, 15 Feb 2008 22:20:06 +0000 (22:20 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Fri, 15 Feb 2008 22:20:06 +0000 (22:20 +0000)
exception message that shows up when a node goes into debug mode.  For
example, in the past one would see this type of message on the
console:

Exception exceptions.OSError: (2, 'No such file or directory', '/tmp/tmpBjmo14') in <bound method _TemporaryFileWrapper.__del__ of <closed file '<fdopen>', mode 'w+b' at 0xb7b108d8>> ignored

This is no longer the case.

source/BootServerRequest.py

index 75fad3c..1af0ece 100644 (file)
@@ -178,12 +178,11 @@ class BootServerRequest:
                      MaxTransferTime= DEFAULT_CURL_MAX_TRANSFER_TIME,
                      FormData= None):
 
-        if hasattr(tempfile, "NamedTemporaryFile"):
-            buffer = tempfile.NamedTemporaryFile()
-            buffer_name = buffer.name
-        else:
-            buffer_name = tempfile.mktemp("MakeRequest")
-            buffer = open(buffer_name, "w+")
+        (fd, buffer_name) = tempfile.mkstemp("MakeRequest-XXXXXX")
+        os.close(fd)
+        buffer = open(buffer_name, "w+b")
+
+        # the file "buffer_name" will be deleted by DownloadFile()
 
         ok = self.DownloadFile(PartialPath, GetVars, PostVars,
                                DoSSL, DoCertCheck, buffer_name,
@@ -191,12 +190,21 @@ class BootServerRequest:
                                MaxTransferTime,
                                FormData)
 
-        # check the code, return the string only if it was successfull
+        # check the ok code, return the string only if it was successfull
         if ok:
             buffer.seek(0)
-            return buffer.read()
+            ret = buffer.read()
         else:
-            return None
+            ret = None
+
+        buffer.close()
+        try:
+            # just in case it is not deleted by DownloadFile()
+            os.unlink(buffer_name)
+        except OSError:
+            pass
+            
+        return ret
 
     def DownloadFile(self, PartialPath, GetVars, PostVars,
                      DoSSL, DoCertCheck, DestFilePath,