pike.git / lib / modules / Filesystem.pmod / Monitor.pmod / basic.pike

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1:   //   // Basic filesystem monitor.   // - // $Id: basic.pike,v 1.32 2010/01/28 14:19:52 grubba Exp $ + // $Id: basic.pike,v 1.33 2010/01/28 15:15:01 grubba Exp $   //   // 2009-07-09 Henrik Grubbström   //      //! Basic filesystem monitor.   //!   //! This module is intended to be used for incremental scanning of   //! a filesystem.      //! The default maximum number of seconds between checks of directories
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:152:   //! Overload this to do something useful.   void stable_data_change(string path, Stdio.Stat st);      //! Flags for @[Monitor]s.   enum MonitorFlags {    MF_RECURSE = 1,    MF_AUTO = 2,    MF_INITED = 4,   };    + protected constant S_IFMT = 0x7ffff000; +    //! Monitoring information for a single filesystem path.   //!   //! @seealso   //! @[monitor()]   protected class Monitor(string path,    MonitorFlags flags,    int max_dir_check_interval,    int file_interval_factor,    int stable_time)   {
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:464:    } else {    file_exists(file, file_stat(file, 1));    }    }    }    // Signal file_exists for path as an end marker.    file_exists(path, st);    }    return 1;    } -  if (!st) { +     if (old_st) { -  +  if (!st || ((old_st->mode & S_IFMT) != (st->mode & S_IFMT))) { +  // File deleted or changed type. +     int delay;    // Propagate deletions to any submonitors.    if (files) {    foreach(files, string file) {    file = canonic_path(Stdio.append_path(path, file));    if (monitors[file]) {    // Adjust next_poll, so that the monitor will be checked soon.    monitors[file]->next_poll = time(1)-1;    monitor_queue->adjust(monitors[file]);    delay = 1;    }    }    }    if (delay) {    // Delay the notification until the submonitors have notified.    st = old_st;    next_poll = time(1);    monitor_queue->adjust(this);    } else { -  if (this_program::flags & MF_AUTO) { +  if (st) { +  // Avoid race when a file has been replaced with a directory +  // or vice versa or similar. +  st = UNDEFINED; +  +  // We will catch the new file at the next poll. +  next_poll = time(1); +  monitor_queue->adjust(this); +  } else if (this_program::flags & MF_AUTO) {    m_delete(monitors, path);    release_monitor(this);    } -  +     file_deleted(path, old_st);    return 1;    } -  } +     return 0;    } -  if (!old_st) { +  } else if (st) { +  // File created. +     last_change = time(1);    file_created(path, st);    if (st->isdir) {    array(string) files = get_dir(path) || ({});    this_program::files = files;    foreach(files, string file) {    file = canonic_path(Stdio.append_path(path, file));    if (monitors[file]) {    // There's already a monitor for the file.    // Assume it has already notified about existance.