Fixed random file saving
authorJosh Karlin <jkarlin@bbn.com>
Thu, 15 Apr 2010 15:19:11 +0000 (15:19 +0000)
committerJosh Karlin <jkarlin@bbn.com>
Thu, 15 Apr 2010 15:19:11 +0000 (15:19 +0000)
sfa/trust/certificate.py
sfa/trust/credential.py

index 7089bd5..c49c50c 100644 (file)
@@ -322,7 +322,10 @@ class Certificate:
    # Save the certificate to a random file in /tmp/
    # @param save_parents If save_parents==True, then also save the parent certificates.
    def save_to_random_tmp_file(self, save_parents=True):
-       filename = "/tmp/cert_%d" % randint(0,999999999)
+       while True:
+           filename = "/tmp/cred_%d" % randint(0,999999999)
+           if not os.path.isfile(filename):
+               break
        self.save_to_file(filename, save_parents)
        return filename
    ##
index 12ef0b7..a9be429 100644 (file)
@@ -402,7 +402,11 @@ class Credential(object):
 
 
     def save_to_random_tmp_file(self):
-        filename = "/tmp/cred_%d" % randint(0,999999999)
+        while True:
+            filename = "/tmp/cred_%d" % randint(0,999999999)
+            if not os.path.isfile(filename):
+                break
+            
         self.save_to_file(filename)
         return filename