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

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:448:    //! Calculate and set a suitable time for the next poll of this monitor.    //!    //! @param st    //! New stat for the monitor.    //!    //! This function is called by @[check()] to schedule the    //! next check.    protected void update(Stdio.Stat st)    {    int delta = max_dir_check_interval || global::max_dir_check_interval; -  this_program::st = st; +  this::st = st;       if (st) {    // Start with a delta proportional to the time since mtime/ctime,    // but bound this to the max setting. A stat in the future will be    // adjusted to the max interval.    int d =    (stable_time || global::stable_time) +    ((time(1) - max(st->mtime, st->ctime)) >> 2);    if (d < 0) d = max_dir_check_interval || global::max_dir_check_interval;    if (d < delta) delta = d;
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:482:    delta = 1 + random(delta);    }       next_poll = time(1) + (delta || 1);    monitor_queue->adjust(this);    }       //! Check if this monitor should be removed automatically.    void check_for_release(int mask, int flags)    { -  if ((this_program::flags & mask) == flags) { +  if ((this::flags & mask) == flags) {    m_delete(monitors, path);    release_monitor(this);    }    }       //! Called to create a sub monitor.    protected void monitor(string path, int flags, int max_dir_interval,    int file_interval_factor, int stable_time)    {    global::monitor(path, flags, max_dir_check_interval,
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:505:       //! 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; +  if (this::files) { +  new_files -= this::files; +  deleted_files = this::files - files;    } -  this_program::files = files; +  this::files = files;    foreach(new_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 created file.    // Let it handle the notification.    m2->check(flags);    }    }; -  if (this_program::flags & MF_RECURSE) { +  if (this::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) {
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:544:    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) { +  if (this::flags & MF_RECURSE) {    // The monitor for the file has probably removed itself,    // or the user has done it by hand, in either case we    // 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.
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:618:    //! @note    //! The return value can not be trusted to return @expr{1@} for all    //! detected changes in recursive mode.    //!    //! @seealso    //! @[check()], @[data_changed()], @[attr_changed()], @[file_created()],    //! @[file_deleted()], @[stable_data_change()]    int(0..1) check(MonitorFlags|void flags)    {    Stdio.Stat st = file_stat(path, 1); -  Stdio.Stat old_st = this_program::st; -  int orig_flags = this_program::flags; -  this_program::flags |= MF_INITED; +  Stdio.Stat old_st = this::st; +  int orig_flags = this::flags; +  this::flags |= MF_INITED;    update(st);    if (!(orig_flags & MF_INITED)) {    // Initialize.    if (st) {    if (st->isdir) {    array(string) files = get_dir(path) || ({}); -  this_program::files = files; +  this::files = files;    foreach(files, string file) {    file = canonic_path(Stdio.append_path(path, file));    if(filter_file(file)) continue;    if (monitors[file]) {    // There's already a monitor for the file.    // Assume it has already notified about existance.    continue;    } -  if (this_program::flags & MF_RECURSE) { +  if (this::flags & MF_RECURSE) {    monitor(file, orig_flags | MF_AUTO | MF_HARD,    max_dir_check_interval,    file_interval_factor,    stable_time);    check_monitor(monitors[file]);    } else {    file_exists(file, file_stat(file, 1));    }    }    }
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:685:    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 {    // The monitor no longer has a link from its parent directory. -  this_program::flags &= ~MF_HARD; +  this::flags &= ~MF_HARD;       // Check if we should remove the monitor.    check_for_release(MF_AUTO, MF_AUTO);    }       file_deleted(path, old_st);    return 1;    }    return 0;    }    } 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; +  this::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.    continue;    } -  if (this_program::flags & MF_RECURSE) { +  if (this::flags & MF_RECURSE) {    monitor(file, orig_flags | MF_AUTO | MF_HARD,    max_dir_check_interval,    file_interval_factor,    stable_time);    check_monitor(monitors[file]);    } else {    file_created(file, file_stat(file, 1));    }    }    }
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:754:    update(st);    return 1;    }   #ifdef HAVE_EVENTSTREAM    else if(orig_flags & MF_RECURSE)    {    // if using FSEvents, we won't receive the name of the file changed,    // so we have to scan for it.    int caught;    array(string) files = get_dir(path) || ({}); -  this_program::files = files; +  this::files = files;    foreach(files, string file) {    file = canonic_path(Stdio.append_path(path, file));    if (monitors[file]) {    if(check_monitor(monitors[file])) caught = 1;    }    }    return caught;    }   #endif /* HAVE_EVENTSTREAM */    return 0;
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:821:    eventstream->callback_func = eventstream_callback;   #elseif HAVE_INOTIFY    instance = System.Inotify._Instance();    file = Stdio.File();    file->assign(instance->fd());    file->set_nonblocking();    file->set_read_callback(inotify_parse);   #endif       if (max_dir_check_interval > 0) { -  this_program::max_dir_check_interval = max_dir_check_interval; +  this::max_dir_check_interval = max_dir_check_interval;    }    if (file_interval_factor > 0) { -  this_program::file_interval_factor = file_interval_factor; +  this::file_interval_factor = file_interval_factor;    }    if (stable_time > 0) { -  this_program::stable_time = stable_time; +  this::stable_time = stable_time;    }    clear();   }      //! Clear the set of monitored files and directories.   //!   //! @note   //! Due to circular datastructures, it's recomended   //! to call this function prior to discarding the object.   void clear()
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1165:   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)   {    int was_nonblocking = !!co_id;    set_blocking(); -  this_program::backend = backend; +  this::backend = backend;    if (was_nonblocking) {    set_nonblocking();    }   }      //! Turn off nonblocking mode.   //!   //! @seealso   //! @[set_nonblocking()]   void set_blocking()
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1245:   #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; +  this::max_dir_check_interval = max_dir_check_interval;    } else { -  this_program::max_dir_check_interval = default_max_dir_check_interval; +  this::max_dir_check_interval = default_max_dir_check_interval;    }   }      //! Set the @[default_file_interval_factor].   void set_file_interval_factor(int file_interval_factor)   {    if (file_interval_factor > 0) { -  this_program::file_interval_factor = file_interval_factor; +  this::file_interval_factor = file_interval_factor;    } else { -  this_program::file_interval_factor = default_file_interval_factor; +  this::file_interval_factor = default_file_interval_factor;    }   }