Branch: Tag:

2012-10-24

2012-10-24 12:37:04 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Filesystem.Monitor: Fix race-condition when monitoring directories.

There was an over-caching issue in the directory monitors for
the following case (everything happend during the same second):

1) A new directory is created.

2) The monitor detects that the directory was created, and checks
its contents -- empty.

3) Some files are added to the directory.

When the monitor returned to check the directory a bit later, it
saw that the mtime was unchanged (since everything above happened
during the same second), so it didn't bother to check the contents.

Now the directory contents are rescanned anyway as long as the
directory hasn't been marked stable.

Also removed some priority bumping in check() that was already
performed properly by status_change().

Fixes [bug 6577 (#6577)] and possibly also some of [bug 6534 (#6534)].

721:    (st->size != old_st->size)) {    last_change = time(1);    if (status_change(old_st, st, orig_flags, flags)) return 1; -  } -  if ((flags & MF_RECURSE) && (st->isdir)) { -  // Check the files in the directory soon. -  foreach(files, string file) { -  file = canonic_path(Stdio.append_path(path, file)); -  Monitor m2 = monitors[file]; -  if (m2) { -  m2->bump(flags); -  } -  } -  } -  if (last_change < time(1) - (stable_time || global::stable_time)) { +  } else if (last_change < time(1) - (stable_time || global::stable_time)) {    last_change = 0x7fffffff;    stable_data_change(path, st);    return 1; -  +  } else if (st->isdir && status_change(old_st, st, orig_flags, flags)) { +  // Directory not stable yet. +  last_change = time(1); +  return 1;    }    return 0;    }