From 5cbe43a5049e33642dced71c943d08cda566e854 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 26 Aug 2009 18:07:14 +0200
Subject: [PATCH] Remove watcher pause file 1h past end time

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 lib/utils.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/utils.py b/lib/utils.py
index 19961ab34..713b3a471 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1951,9 +1951,17 @@ def FormatTime(val):
   return time.strftime("%F %T", time.localtime(val))
 
 
-def ReadWatcherPauseFile(filename, now=None):
+def ReadWatcherPauseFile(filename, now=None, remove_after=3600):
   """Reads the watcher pause file.
 
+  @type filename: string
+  @param filename: Path to watcher pause file
+  @type now: None, float or int
+  @param now: Current time as Unix timestamp
+  @type remove_after: int
+  @param remove_after: Remove watcher pause file after specified amount of
+    seconds past the pause end time
+
   """
   if now is None:
     now = time.time()
@@ -1969,10 +1977,18 @@ def ReadWatcherPauseFile(filename, now=None):
     try:
       value = int(value)
     except ValueError:
+      logging.warning(("Watcher pause file (%s) contains invalid value,"
+                       " removing it"), filename)
+      RemoveFile(filename)
       value = None
 
     if value is not None:
-      if now > value:
+      # Remove file if it's outdated
+      if now > (value + remove_after):
+        RemoveFile(filename)
+        value = None
+
+      elif now > value:
         value = None
 
   return value
-- 
GitLab