From 6ebf58965e6b9f78027c94abeb58dca8bae04d86 Mon Sep 17 00:00:00 2001
From: Chris Bainbridge <chris.bainbridge@gmail.com>
Date: Fri, 29 May 2015 16:32:57 +0100
Subject: [PATCH] Detect moved file when using inotify polling

Commit 15f82c7 ("used pyinotify as change detection system when
available") introduced a regression where editing a file in vim with
default settings (writebackup=auto) would no longer cause the dev server
to be restarted. On a write, vim moves the monitored file to a backup
path, and then creating a new file in the original. The new file is not
monitored as it has a different inode. Fix this by also watching for
inotify events IN_DELETE_SELF and IN_MOVE_SELF.
---
 django/utils/autoreload.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index f4ac497..6efd6c4 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -175,7 +175,9 @@ def inotify_code_changed():
             pyinotify.IN_ATTRIB |
             pyinotify.IN_MOVED_FROM |
             pyinotify.IN_MOVED_TO |
-            pyinotify.IN_CREATE
+            pyinotify.IN_CREATE |
+            pyinotify.IN_DELETE_SELF |
+            pyinotify.IN_MOVE_SELF
         )
         for path in gen_filenames(only_new=True):
             wm.add_watch(path, mask)
-- 
2.1.4

