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

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:333:    //!    //! @note    //! For directories, @[file_created()] will be called for the subpaths    //! before the call for the directory itself. This can be used to detect    //! when the initialization for a directory is finished.    //!    //! Called by @[check()] and @[check_monitor()] the first time a monitored    //! path is checked (and only if it exists).    protected void file_exists(string path, Stdio.Stat st)    { +  int t = time(1);    call_callback(global::file_exists, path, st); -  +  if (st->mtime + (stable_time || global::stable_time) >= t) { +  // Not stable yet! We guess that the mtime is a +  // fair indication of when the file last changed. +  last_change = st->mtime;    } -  +  }       //! File creation callback.    //!    //! @param st    //! Status information for @[path] as obtained by    //! @expr{file_stat(path, 1)@}.    //!    //! This function is called when either a monitored path has started    //! existing, or when a new file or directory has been added to a    //! monitored directory.
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:475:    {    global::monitor(path, flags, max_dir_check_interval,    file_interval_factor, stable_time);    }       //! Called when the status has changed for an existing file.    protected int(0..1) status_change(Stdio.Stat old_st, Stdio.Stat st,    int orig_flags, int flags)    {    if (st->isdir) { +  int res = 0;    array(string) files = get_dir(path) || ({});    array(string) new_files = files;    array(string) deleted_files = ({});    if (this_program::files) {    new_files -= this_program::files;    deleted_files = this_program::files - files;    }    this_program::files = files;    foreach(new_files, string file) { -  if(filter_file(file)) continue; +  res = 1;    file = canonic_path(Stdio.append_path(path, file)); -  +  if(filter_file(file)) continue;    Monitor m2 = monitors[file];    mixed err = catch {    if (m2) {    // We have a separate monitor on the created file.    // Let it handle the notification.    m2->check(flags);    }    };    if (this_program::flags & MF_RECURSE) {    monitor(file, orig_flags | MF_AUTO | MF_HARD,    max_dir_check_interval,    file_interval_factor,    stable_time);    monitors[file]->check();    } else if (!m2) {    file_created(file, file_stat(file, 1));    }    }    foreach(deleted_files, string file) { -  +  res = 1;    file = canonic_path(Stdio.append_path(path, file)); -  +  if(filter_file(file)) continue;    Monitor m2 = monitors[file];    mixed err = catch {    if (m2) {    // We have a separate monitor on the deleted file.    // Let it handle the notification.    m2->check(flags);    }    };    if (this_program::flags & MF_RECURSE) {    // The monitor for the file has probably removed itself,
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:527:    // don't need to do anything more here.    } else if (!m2) {    file_deleted(file);    }    if (err) throw(err);    }    if (flags & MF_RECURSE) {    // Check the remaining files in the directory soon.    foreach(((files - new_files) - deleted_files), string file) {    file = canonic_path(Stdio.append_path(path, file)); +  if(filter_file(file)) continue;    Monitor m2 = monitors[file];    if (m2) {    m2->bump(flags); -  +  } else { +  // Lost update due to race-condition: +  // +  // Exist ==> Deleted ==> Exists +  // +  // with no update of directory inbetween. +  // +  // Create the lost submonitor again. +  res = 1; +  monitor(file, orig_flags | MF_AUTO | MF_HARD, +  max_dir_check_interval, +  file_interval_factor, +  stable_time); +  monitors[file]->check();    }    }    } -  if (sizeof(new_files) || sizeof(deleted_files)) return 1; +  return res;    } else {    attr_changed(path, st);    return 1;    }    return 0;    }       //! Check for changes.    //!    //! @param flags
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1090:   }      //! Backend to use.   //!   //! If @expr{0@} (zero) - use the default backend.   protected Pike.Backend backend;      //! Call-out identifier for @[backend_check()] if in   //! nonblocking mode.   //! + //! Set to @expr{1@} when non_blocking mode without call_outs + //! is in use. + //!   //! @seealso   //! @[set_nonblocking()], @[set_blocking()]   protected mixed co_id;      //! Change backend.   //!   //! @param backend   //! Backend to use. @expr{0@} (zero) for the default backend.   void set_backend(Pike.Backend|void backend)   {
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1131:   //! Backend check callback function.   //!   //! This function is intended to be called from a backend,   //! and performs a @[check()] followed by rescheduling   //! itself via a call to @[set_nonblocking()].   //!   //! @seealso   //! @[check()], @[set_nonblocking()]   protected void backend_check()   { -  co_id = 0; +  if (co_id != 1) co_id = 0;    int t;    mixed err = catch {    t = check(0);    }; - #if HAVE_EVENTSTREAM - // if we are using FSEvents, we don't want to run this check more than once to prime the pumps. - #elseif HAVE_INOTIFY - // if we are using Inotify, we don't want to run this check more than once to prime the pumps. - #else +     set_nonblocking(t); - #endif /* HAVE_EVENTSTREAM */ +     if (err) throw(err);   }      //! Turn on nonblocking mode.   //!   //! @param t   //! Suggested time in seconds until next call of @[check()].   //!   //! Register suitable callbacks with the backend to automatically   //! call @[check()].
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1172:   //! @[set_blocking()], @[check()].   void set_nonblocking(int|void t)   {    if (co_id) return;    if (zero_type(t)) {    Monitor m = monitor_queue->peek();    t = (m && m->next_poll - time(1)) || max_dir_check_interval;    if (t > max_dir_check_interval) t = max_dir_check_interval;    if (t < 0) t = 0;    } - // if (backend) co_id = backend->call_out(backend_check, t); - // else co_id = call_out(backend_check, t); + #if HAVE_EVENTSTREAM +  // If we are using FSEvents, we don't need any call_outs. +  co_id = 1; + #elseif HAVE_INOTIFY +  // If we are using Inotify, we don't need any call_outs. +  co_id = 1; + #else +  if (backend) co_id = backend->call_out(backend_check, t); +  else co_id = call_out(backend_check, t); + #endif /* HAVE_EVENTSTREAM */   }      //! Set the @[default_max_dir_check_interval].   void set_max_dir_check_interval(int max_dir_check_interval)   {    if (max_dir_check_interval > 0) {    this_program::max_dir_check_interval = max_dir_check_interval;    } else {    this_program::max_dir_check_interval = default_max_dir_check_interval;    }