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.28 2009/10/19 14:23:45 grubba Exp $ + // $Id: basic.pike,v 1.29 2009/10/20 14:33:26 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:257:    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) || ({});    this_program::files = files;    foreach(files, string file) { -  file = Stdio.append_path(path, 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) {    monitor(file, orig_flags | MF_AUTO,    max_dir_check_interval,    file_interval_factor,    stable_time);
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:319:    return 1;    }    }    return 0;    }    if (!old_st) {    last_change = time(1);    if (file_created) {    file_created(path, st);    } +  if (st->isdir) { +  array(string) files = get_dir(path) || ({}); +  this_program::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) { +  monitor(file, orig_flags | MF_AUTO, +  max_dir_check_interval, +  file_interval_factor, +  stable_time); +  check_monitor(monitors[file]); +  } else if (file_created) { +  file_created(file, file_stat(file, 1)); +  } +  } +  }    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) 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); +  file = canonic_path(Stdio.append_path(path, file));    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,    max_dir_check_interval,    file_interval_factor,    stable_time);    monitors[file]->check();    } else if (!m2 && file_created) {    file_created(file, file_stat(file, 1));    }    }    foreach(deleted_files, string file) { -  file = Stdio.append_path(path, file); +  file = canonic_path(Stdio.append_path(path, file));    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,    // 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_deleted(file);    }    if (err) throw(err);    }    if (flags & MF_RECURSE) {    // Check the remaining files in the directory.    foreach(((files - new_files) - deleted_files), string file) { -  file = Stdio.append_path(path, file); +  file = canonic_path(Stdio.append_path(path, file));    Monitor m2 = monitors[file];    if (m2) {    m2->check(flags);    }    }    }    if (sizeof(new_files) || sizeof(deleted_files)) return 1;    } else {    if (data_changed) {    data_changed(path);
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:397:    }    if (attr_changed) {    attr_changed(path, st);    }    return 1;    }    }    if ((flags & MF_RECURSE) && (st->isdir)) {    // Check the files in the directory.    foreach(files, string file) { -  file = Stdio.append_path(path, file); +  file = canonic_path(Stdio.append_path(path, file));    Monitor m2 = monitors[file];    if (m2) {    m2->check(flags);    }    }    }    if (last_change < time(1) - (stable_time || global::stable_time)) {    last_change = 0x7fffffff;    if (stable_data_change) {    stable_data_change(path, st);