kopia lustrzana https://github.com/c9/core
move watcher code to the server
rodzic
745511f8b5
commit
14f6a65ea5
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue