Modules (188)

FileWatcherManager

Description

Dependencies

This module has no dependencies

Functions

Private

_unwatchPath

Un-watch a file or directory.

path string
File or directory to unwatch.
function _unwatchPath(path) {
    var watcher = _watcherMap[path];

    if (watcher) {
        try {
            watcher.close();
        } catch (err) {
            console.warn("Failed to unwatch file " + path + ": " + (err && err.message));
        } finally {
            delete _watcherMap[path];
        }
    }
}

normalizeStats

Transform Node's native fs.stats to a format that can be sent through domain

nodeFsStats stats
Node's fs.stats result
Returns: object
Can be consumed by new FileSystemStats(object); in Brackets
function normalizeStats(nodeFsStats) {
    // current shell's stat method floors the mtime to the nearest thousand
    // which causes problems when comparing timestamps
    // so we have to round mtime to the nearest thousand too
    var mtime = Math.floor(nodeFsStats.mtime.getTime() / 1000) * 1000;

    // from shell: If "filename" is a symlink,
    // realPath should be the actual path to the linked object
    // not implemented in shell yet
    return {
        isFile: nodeFsStats.isFile(),
        isDirectory: nodeFsStats.isDirectory(),
        mtime: mtime,
        size: nodeFsStats.size,
        realPath: null,
        hash: mtime
    };
}
Public API

unwatchAll

Un-watch all files and directories.

function unwatchAll() {
    var path;

    for (path in _watcherMap) {
        if (_watcherMap.hasOwnProperty(path)) {
            unwatchPath(path);
        }
    }
}

function emitChange(event, parentDirPath, entryName, nodeFsStats) {
    // make sure stats are normalized for domain transfer
    var statsObj = nodeFsStats ? normalizeStats(nodeFsStats) : null;
    _domainManager.emitEvent("fileWatcher", "change", [event, parentDirPath, entryName, statsObj]);
}

exports.setDomainManager = setDomainManager;
exports.setWatcherImpl = setWatcherImpl;
exports.unwatchPath = unwatchPath;
exports.watchPath = watchPath;
exports.unwatchAll = unwatchAll;
exports.emitChange = emitChange;
Public API

unwatchPath

Un-watch a file or directory. For directories, unwatch all descendants.

path string
File or directory to unwatch.
function unwatchPath(path) {
    Object.keys(_watcherMap).forEach(function (keyPath) {
        if (keyPath.indexOf(path) === 0) {
            _unwatchPath(keyPath);
        }
    });
}
Public API

watchPath

Watch a file or directory.

path string
File or directory to watch.
ignored Array<string>
List of entries to ignore during watching.
function watchPath(path, ignored) {
    if (_watcherMap.hasOwnProperty(path)) {
        return;
    }
    return _watcherImpl.watchPath(path, ignored, _watcherMap, _domainManager);
}