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.26 2009/10/12 15:00:11 grubba Exp $ + // $Id: basic.pike,v 1.27 2009/10/13 12:39:20 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:254:    // werror("Checking monitor %O...\n", this);    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;    update(st);    if (!(orig_flags & MF_INITED)) {    // Initialize.    if (st) {    if (st->isdir) { -  array(string) files = get_dir(path); +  array(string) files = get_dir(path) || ({});    this_program::files = files;    foreach(files, string file) {    file = 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) {    monitor(file, orig_flags | MF_AUTO,
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:305:    last_change = time(1);    if (file_created) {    file_created(path, st);    }    return 1;    }    if ((st->mtime != old_st->mtime) || (st->ctime != old_st->ctime) ||    (st->size != old_st->size)) {    last_change = time(1);    if (st->isdir) { -  array(string) files = get_dir(path); +  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) {    file = Stdio.append_path(path, file);    Monitor m2 = monitors[file];
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:712:   //! @[monitor()]   int check(int|void max_wait, int|void max_cnt,    mapping(string:int)|void ret_stats)   {    int scan_cnt = max_cnt;    int scan_wait = max_wait;    while(1) {    int ret = max_dir_check_interval;    int cnt;    int t = time(); -  Monitor m; +     if (sizeof(monitors)) { -  while ((m = monitor_queue->peek()) && -  m <= t) { +  Monitor m; +  while ((m = monitor_queue->peek()) && (m->next_poll <= t)) {    cnt += check_monitor(m); -  if (--scan_cnt) break; +  if (!(--scan_cnt)) { +  m = monitor_queue->peek(); +  break;    } -  +  }    if (m) {    ret = m->next_poll - t;    if (ret <= 0) ret = 1;    } else {    scan_cnt--;    }    }    if (cnt || !scan_wait || !scan_cnt) {    if (ret_stats) {    ret_stats->num_monitors = sizeof(monitors);