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

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:888:   }      //! Event callback for Inotify.   protected void inotify_event(int wd, int event, int cookie, string(8bit) path)   {    MON_WERR("inotify_event(%O, %s, %O, %O)...\n",    wd, System.Inotify.describe_mask(event), cookie, path);    string(8bit) icookie = inotify_cookie(wd);    Monitor m;    if((m = monitors[icookie])) { +  if (sizeof (path)) { +  string full_path = canonic_path (combine_path (m->path, path)); +  // We're interested in the sub monitor, if it exists. +  if (Monitor submon = monitors[full_path]) +  m = submon; +  } +  } +  +  if (m) {    if (event == System.Inotify.IN_IGNORED) {    // This Inotify watch has been removed    // (either by us or automatically).    MON_WERR("### Monitor watch descriptor %d is no more.\n", wd);    m_delete(monitors, icookie);    }    mixed err = catch { -  +  if (event & System.Inotify.IN_CLOSE_WRITE) +  // File marked as stable immediately. +  m->last_change = -0x7fffffff;    m->check(0);    };    if (err) {    master()->handler_error(err);    }    } else { -  // Unknown monitor. Perform a full scan. -  MON_WERR("### Unknown monitor! Performing full scan.\n"); -  check_all(); -  // No need to look at the other entries if we're going to do -  // a full scan. +  MON_WERR("No monitor found for path %O.\n", path);    }   }      //! Inotify-accellerated @[Monitor].   protected class InotifyMonitor   {    inherit Monitor;       protected int wd = -1;    int `accellerated() { return wd != -1; }
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:963: Inside #if undefined(INHIBIT_INOTIFY_MONITOR)
   MON_WERR("Creating Inotify monitor instance.\n");    instance = System.Inotify._Instance();    if (backend) instance->set_backend(backend);    instance->set_event_callback(inotify_event);    if (co_id) {    MON_WERR("Turning on nonblocking mode for Inotify.\n");    instance->set_nonblocking();    }    }    -  catch { +  Stdio.Stat st = file_stat (path, 1); +  if (st && st->isdir) { +  // Note: We only want to add watchers on directories. File +  // notifications will take place on the directory watch +  // descriptors. Expansion of the path to cover notifications +  // on individual files is handled in the inotify_event +  // callback. +  +  if (mixed err = 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); +  System.Inotify.IN_CREATE | +  System.Inotify.IN_CLOSE_WRITE);    -  MON_WERR("Registered %O with %O ==> %d.\n", path, instance, new_wd); +     if (new_wd != -1) { -  +  MON_WERR("Registered %O with %O ==> %d.\n", path, instance, new_wd);    // We shouldn't need to be polled.    if (!initial) {    MON_WERR("Unregistering from polling.\n");    release_monitor(this);    }    wd = new_wd;    monitors[inotify_cookie(wd)] = this;    if (initial) {    // NB: Inotify seems to not notify on preexisting paths,    // so we need to strap it along.    check();    } -  return; +     } -  }; +  }) { +  master()->handle_error (err); +  } +  } +  +  return; +    #endif /* !INHIBIT_INOTIFY_MONITOR */    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