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

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:10:   //!   //! This module is intended to be used for incremental scanning of   //! a filesystem.   //!   //! Supports FSEvents on MacOS X and Inotify on Linux to provide low   //! overhead monitoring; other systems use a less efficient polling approach.   //!   //! @seealso   //! @[System.FSEvents], @[System.Inotify]    + #ifdef FILESYSTEM_MONITOR_DEBUG + #define MON_WERR(X...) werror(X) + #else + #define MON_WERR(X...) + #endif +    //! The default maximum number of seconds between checks of directories   //! in seconds.   //!   //! This value is multiplied with @[default_file_interval_factor] to   //! get the corresponding default maximum number of seconds for files.   //!   //! The value can be changed by calling @[create()].   //!   //! The value can be overridden for individual files or directories   //! by calling @[monitor()].
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:189:    array(string) files;       //! Register the @[Monitor] with the monitoring system.    //!    //! @param initial    //! Indicates that the @[Monitor] is newly created.    protected void register_path(int|void initial)    {    if (initial) {    // We need to be polled... +  MON_WERR("Registering %O for polling.\n", path);    monitor_queue->push(this);    }    }       //! Unregister the @[Monitor] from the monitoring system.    //!    //! @param dying    //! Indicates that the @[Monitor] is being destructed.    protected void unregister_path(int|void dying)    { -  if (!dying) { -  // We now need to be polled... +  if (dying) { +  // We are going away permanently, so remove ourselves from +  // from the monitor_queue. +  MON_WERR("Unregistering %O from polling.\n", path);    monitor_queue->remove(this);    }    }       int `<(mixed m) { return next_poll < m; }    int `>(mixed m) { return next_poll > m; }       void create()    {    Element::create(this);
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:557:    //!    //! @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)    { +  MON_WERR("Checking monitor %O...\n", this);    Stdio.Stat st = file_stat(path, 1);    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) || ({});
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:690:    return 1;    } else if (last_change != 0x7fffffff &&    st->isdir && status_change(old_st, st, orig_flags, flags)) {    // Directory not stable yet.    last_change = time(1);    update(st);    return 1;    }    return 0;    } +  +  protected void destroy() +  { +  unregister_path(1);    } -  + }      //   // Some necessary setup activities for systems that provide   // filesystem event monitoring   //   #if constant(System.FSEvents.EventStream)   #define HAVE_EVENTSTREAM 1   #endif      #if constant(System.Inotify)
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:786: Inside #if HAVE_EVENTSTREAM
  }      #elseif HAVE_INOTIFY      protected System.Inotify._Instance instance;   protected Stdio.File file;      //! Read callback for events on the Inotify file.   protected void inotify_parse(mixed id, string data)   { +  MON_WERR("inotify_parse(%O, %O)...\n", id, data);    while (sizeof(data)) {    array a;    mixed err = catch {    a = System.Inotify.parse_event(data);    };       if (err) {    // TODO: might have a partial event struct here which gets completed    // by the next call?? maybe add an internal buffer. -  werror("Could not parse inotify event: %s\n", describe_error(err)); +  MON_WERR("Could not parse inotify event: %s\n", describe_error(err));    return;    } -  +  MON_WERR("### Event: %O\n", a);    string path;    path = a[3];    if(path && monitors[path]) {    monitors[path]->check(0);    } else {    // No need to look at the other entries if we're going to do    // a full scan.    check_all();    return;    }
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:826:    inherit Monitor;       protected int wd = -1;    int `accellerated() { return wd != -1; }       protected void register_path(int|void initial)    {    if (wd != -1) return;       if (initial && !instance) { +  MON_WERR("Creating Inotify monitor instance.\n");    instance = System.Inotify._Instance();    file = Stdio.File();    if (backend) file->set_backend(backend);    file->assign(instance->fd());    file->set_nonblocking();    file->set_read_callback(inotify_parse); -  +  MON_WERR("File: %O\n", file);    }       catch {    int new_wd = instance->add_watch(path,    System.Inotify.IN_MOVED_FROM |    System.Inotify.IN_UNMOUNT |    System.Inotify.IN_MOVED_TO |    System.Inotify.IN_MASK_ADD |    System.Inotify.IN_MOVE_SELF |    System.Inotify.IN_DELETE |    System.Inotify.IN_MOVE |    System.Inotify.IN_MODIFY |    System.Inotify.IN_ATTRIB |    System.Inotify.IN_DELETE_SELF |    System.Inotify.IN_CREATE);    -  +  MON_WERR("Registered %O with %O ==> %d.\n", path, instance, new_wd);    if (new_wd != -1) {    // We shouldn't need to be polled.    if (!initial) { -  +  MON_WERR("Unregistering from polling.\n");    release_monitor(this);    }    wd = new_wd;    return;    }    }; -  +  MON_WERR("Registering %O for polling.\n", path);    ::register_path(initial);    }       protected void unregister_path(int|void dying)    { -  +  MON_WERR("Unregistering %O...\n", path);    if (wd != -1) {    // NB: instance may be null if the main object has been destructed    // and we've been called via a destroy().    if (instance) { -  +  MON_WERR("### Unregistering from inotify.\n");    instance->rm_watch(wd);    }    wd = -1;    if (!dying) {    // We now need to be polled... -  +  MON_WERR("Registering for polling.\n");    monitor_queue->push(this);    }    }    ::unregister_path(dying);    } -  -  protected void destroy() -  { -  unregister_path(1); +    } - } +    #endif /* HAVE_EVENTSTREAM || HAVE_INOTIFY */      //! Canonicalize a path.   //!   //! @param path   //! Path to canonicalize.   //!   //! @returns   //! The default implementation returns @expr{combine_path(path, ".")@},   //! i.e. no trailing slashes.
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1085:    monitors[path] = m;    // NB: Registering with the monitor_queue is done as    // needed by register_path() as called by create().    }   }      int filter_file(string path)   {    array x = path/"/";    foreach(x;; string pc) -  if(pc && strlen(pc) && pc[0]=='.' && pc != "..") {/* werror("skipping %O\n", path); */ return 1; } +  if(pc && strlen(pc) && pc[0]=='.' && pc != "..") { +  MON_WERR("skipping %O\n", path); +  return 1; +  }       return 0;   }      //! Release a @[path] from monitoring.   //!   //! @param path   //! Path to stop monitoring.   //!   //! @param flags