Watchdog: Ignore hidden & removed files

Closes #2558
This commit is contained in:
Gina Häußge committed 2018-04-27 16:17:04 +02:00
1 parent 3ebb36f877
commit 9e32439f44
1 file changed
+15 -3
+15 -3
View File
@@ -71,16 +71,28 @@ class GcodeWatchdogHandler(watchdog.events.PatternMatchingEventHandler):
self._logger.exception("There was an error while processing the file {} in the watched folder".format(path))
def on_created(self, event):
thread = threading.Thread(target=self._repeatedly_check, args=(event.src_path,))
path = event.src_path
if octoprint.util.is_hidden_path(path):
return
thread = threading.Thread(target=self._repeatedly_check, args=(path,))
thread.daemon = True
thread.start()
def _repeatedly_check(self, path, interval=1, stable=5):
last_size = os.stat(path).st_size
try:
last_size = os.stat(path).st_size
except:
return
countdown = stable
while True:
new_size = os.stat(path).st_size
try:
new_size = os.stat(path).st_size
except:
return
if new_size == last_size:
self._logger.debug("File at {} is no longer growing, counting down: {}".format(path, countdown))
countdown -= 1