From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Date: Fri, 11 Feb 2011 15:09:02 +0000 (+0100)
Subject: trashing existing tmp file if older than 5 minutes
X-Git-Tag: plcapi-5.0-29~4
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1fc9f3ed3c4758703cc149e1ae67c6deccd7024a;p=plcapi.git

trashing existing tmp file if older than 5 minutes
---

diff --git a/PLC/Methods/GetBootMedium.py b/PLC/Methods/GetBootMedium.py
index 82484097..f050840c 100644
--- a/PLC/Methods/GetBootMedium.py
+++ b/PLC/Methods/GetBootMedium.py
@@ -312,8 +312,16 @@ class GetBootMedium(Method):
                     raise PLCInvalidArgument, "File %s not under %s"%(filename,self.WORKDIR)
 
             ### output should not exist (concurrent runs ..)
+            # numerous reports of issues with this policy
+            # looks like people sometime suspend/cancel their download
+            # and this leads to the old file sitting in there forever
+            # so, if the file is older than 5 minutes, we just trash
+            grace=5
+            if os.path.exists(filename) and os.path.getmtime(filename)-time.time() >= (grace*60):
+                os.unlink(filename)
             if os.path.exists(filename):
-                raise PLCInvalidArgument, "Resulting file %s already exists"%filename
+                raise PLCInvalidArgument, "Resulting file %s already exists - please try again in %d minutes"%\
+                    (filename,grace)
 
             ### we can now safely create the file,
             ### either we are admin or under a controlled location