Watchdog: Doesn't detect file modification with vim on OSX 10.7

Created on 13 Aug 2011  路  7Comments  路  Source: gorakhargosh/watchdog

At first, FSEvents-support works beautifully on OSX now. Thank you!

Unfortunately, watchdot cannot detect vim saving modifications to an existing file on a mac.

I traced it here:
https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/utils/dirsnapshot.py#L95

I have no idea why, but it seems that when vim saves a file, it gets a new inode number and watchdog cannot categorize the event and ignores it.

An example stat info from ref_dirsnap:

posix.stat_result(st_mode=33188, st_ino=51180728, st_dev=234881027L, st_nlink=1, st_uid=501, st_gid=20, st_size=2756, st_atime=1313212427, st_mtime=1313212426, st_ctime=1313212426)

The same stat info from dirsnap:

posix.stat_result(st_mode=33188, st_ino=51180736, st_dev=234881027L, st_nlink=1, st_uid=501, st_gid=20, st_size=2756, st_atime=1313212514, st_mtime=1313212514, st_ctime=1313212514)

Some other editors, e.g. TextMate work correctly (st_ino doesn't change and modification is detected correctly).

All 7 comments

For those, who cannot wait for fix (to either vim or watchog; I don't know, which one is correct), you can make watchdog a little dummier in detecting modifications:

diff --git a/src/watchdog/utils/dirsnapshot.py b/src/watchdog/utils/dirsnapshot.py
index dbd121b..0d91fcc 100644
--- a/src/watchdog/utils/dirsnapshot.py
+++ b/src/watchdog/utils/dirsnapshot.py
@@ -92,7 +92,7 @@ class DirectorySnapshotDiff(object):
         for path, stat_info in dirsnap.stat_snapshot.items():
             if path in ref_dirsnap.stat_snapshot:
                 ref_stat_info = ref_dirsnap.stat_info(path)
-                if stat_info.st_ino == ref_stat_info.st_ino and stat_info.st_mtime != ref_stat_info.
+                if stat_info.st_mtime != ref_stat_info.st_mtime:
                     if stat.S_ISDIR(stat_info.st_mode):
                         self._dirs_modified.append(path)
                     else:

When you save a file called foobar.txt using Vim, it essentially creates
a foobar.txt.swp file in the same directory as the file, deletes the old
one, and renames the .swp file to the original filename. So, it would be
wiser to use a pattern with a command instead like so :

$ watchmedo log --pattern="*.swp;*.py;*.~;*.rb" --recursive .

Update:

Here's a better way. You can disable swap file creation in Vim.

:set noswapfile

in your ~/.vimrc and you don't need to edit either watchdog or
write a pattern. This will keep monitoring working as you expect it to.

I also found out that there's on option for that in vim.

:set nowritebackup

Now there's a plenty of options to make either vim or watchdog behave :)

I thank you very much and consider this closed.

One final comment. Actually, I had to disable backups completely by

:set nobackup
:set nowritebackup

(or set those in ~/.vimrc) to prevent vim for creating a new file on save and watchdog detect it.

I also wonder, why :set nowswapfile had no effect for me. Anyway, I'm quite happy now.

I'm facing the same issue with Espresso editor (on OS X) which unfortunately has no configuration option for that. According to ls -i, Espresso creates new file on every save. Any changes that this could be resolved on watchdog level?

Thanks for watchdog, and for this issue! This ended up working for me as well:

:set nobackup
:set nowritebackup

+1 to reopen. Users who don't happen upon the workaround here will assume watchdog is broken--I did. Meanwhile, similar tools like watchr "just work", without changing any Vim settings. watchdog is awesome, but I wish I didn't have to change my vimrc in order to use it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nikolaissue picture Nikolaissue  路  6Comments

alciomarhollanda picture alciomarhollanda  路  5Comments

gilles380 picture gilles380  路  3Comments

alt3red picture alt3red  路  3Comments

mccarthyryanc picture mccarthyryanc  路  5Comments