move watcher code to the server

pull/314/merge
nightwing 2016-06-15 00:28:48 +04:00
rodzic 745511f8b5
commit 14f6a65ea5
2 zmienionych plików z 33 dodań i 20 usunięć

33
node_modules/vfs-local/localfs.js wygenerowano vendored
Wyświetl plik

@ -1039,7 +1039,7 @@ module.exports = function setup(fsOptions) {
if (!exists || options.overwrite || isSamePath) {
// Rename the file
fs.rename(frompath, topath, function (err) {
renameWatchedFile(frompath, topath, function (err) {
if (err) {
if (err.code == 'ENOENT' && options.mkdirP != false) {
options.mkdirP = false;
@ -1364,7 +1364,9 @@ module.exports = function setup(fsOptions) {
close();
};
this.resume = function(callback) {
this.resume = function(callback, newPath) {
if (newPath)
path = newPath;
if (!listeners.length)
return callback();
watch(callback);
@ -1433,6 +1435,33 @@ module.exports = function setup(fsOptions) {
});
}
}
function renameWatchedFile(frompath, topath, callback) {
var removed = [];
Object.keys(fileWatchers).forEach(function(path) {
if (path.slice(0, frompath.length) == frompath && (path[frompath.length] == "/" || !path[frompath.length])) {
var watchers = fileWatchers[path].slice();
watchers.forEach(function(w) {
w.pause();
});
removed.push({
relpath: path.slice(frompath.length),
watchers: watchers
});
}
});
fs.rename(frompath, topath, function(err) {
var root = err ? frompath : topath;
removed.forEach(function(x) {
var path = root + x.relpath;
x.watchers.forEach(function(w) {
w.resume(function() {
}, path);
});
});
callback(err);
});
}
function connect(port, options, callback) {
var retries = options.hasOwnProperty('retries') ? options.retries : 5;

Wyświetl plik

@ -48,23 +48,8 @@ define(function(require, exports, module) {
fs.on("beforeWriteFile", ignoreHandler, plugin);
fs.on("afterWriteFile", doneHandler, plugin);
fs.on("beforeRename", function(e) {
e.watchers = [];
Object.keys(handlers).forEach(function(path) {
if (path == e.path || path.startsWith(e.path + "/")) {
if (unwatch(path))
e.watchers.push(path.slice(e.path.length));
}
});
ignoreHandler(e);
}, plugin);
fs.on("afterRename", function(e) {
doneHandler(e);
var toPath = e.result[0] ? e.path : e.args[1];
e.watchers.forEach(function(path) {
watch(toPath + path);
});
}, plugin);
fs.on("beforeRename", ignoreHandler, plugin);
fs.on("afterRename", doneHandler, plugin);
fs.on("beforeMkdir", ignoreHandler, plugin);
fs.on("afterMkdir", doneHandler, plugin);
fs.on("beforeMkdirP", ignoreHandler, plugin);
@ -239,7 +224,6 @@ define(function(require, exports, module) {
fs.unwatch(path, handlers[path]);
emit("unwatch", { path: path });
delete handlers[path];
return true;
} else {
handlers[path].unwatchScheduled = true;
}