0e92c9363422 v0.2.1

Don't choke on deleted files.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 24 Nov 2012 13:54:18 -0500
parents 154eb9cb113d
children 77798c15666a
branches/tags v0.2.1
files peat

Changes

--- a/peat	Sat Nov 24 13:48:39 2012 -0500
+++ b/peat	Sat Nov 24 13:54:18 2012 -0500
@@ -14,7 +14,7 @@
                               # Repeat commands! #
                                ##################
 
-import os, subprocess, sys, time
+import errno, os, subprocess, sys, time
 from optparse import OptionParser
 
 
@@ -36,8 +36,16 @@
 def check(paths):
     cutoff = int(time.time() - interval)
     for p in paths:
-        if os.stat(p).st_mtime >= cutoff:
-            return True
+        try:
+            if os.stat(p).st_mtime >= cutoff:
+                return True
+        except OSError, e:
+            # If the file has been deleted since we started watching, don't
+            # worry about it.
+            if e.errno == errno.ENOENT:
+                pass
+            else:
+                raise
     return False
 
 def run():