Permalink
Browse files

Fixing check for file deletion in two different ways 1) through dir c…

…hange 2) through file change. Sometimes things can get messy depending on what version of node you're running. For more info, check: nodejs/node-v0.x-archive#4027 (fix #37)
  • Loading branch information...
arboleya committed Nov 18, 2012
1 parent af74a61 commit 7e069b7250f173d3957606e0513c2ab0346c05e0
Showing with 25 additions and 14 deletions.
  1. +15 −6 lib/toaster.js
  2. +10 −8 src/toaster/utils/fs-util.coffee
View
@@ -514,12 +514,19 @@ var toaster = exports.toaster = {};
});
}
return fs.watchFile(filepath, {
- interval: 250
+ persistent: true,
+ interval: 30
}, function(curr, prev) {
var ctime, mtime;
mtime = curr.mtime.valueOf() !== prev.mtime.valueOf();
ctime = curr.ctime.valueOf() !== prev.ctime.valueOf();
- if (mtime || ctime) {
+ if (curr.nlink === 0) {
+ return typeof onchange === "function" ? onchange({
+ type: "file",
+ path: filepath,
+ action: "deleted"
+ }) : void 0;
+ } else if (mtime || ctime) {
return typeof onchange === "function" ? onchange({
type: "file",
path: filepath,
@@ -590,7 +597,8 @@ var toaster = exports.toaster = {};
on_folder_change = FnUtil.proxy(FsUtil._on_folder_change, folderpath);
fs.unwatchFile(folderpath);
return fs.watchFile(folderpath, {
- interval: 250
+ persistent: true,
+ interval: 30
}, on_folder_change);
}
};
@@ -853,17 +861,18 @@ var toaster = exports.toaster = {};
this.raw = fs.readFileSync(this.realpath, "utf-8");
this.dependencies_collapsed = [];
this.baseclasses = [];
- this.filepath = this.realpath.replace(this.folderpath, "").substr(1);
+ this.filepath = this.realpath.replace(this.folderpath, "");
if (this.alias != null) {
this.filepath = pn("" + this.alias + "/" + this.filepath);
}
+ this.filepath = this.filepath.replace(/^[\/]+/, "");
this.filename = /[\w-]+\.[\w-]+/.exec(this.filepath)[0];
this.filefolder = this.filepath.replace("/" + this.filename, "") + "/";
this.namespace = "";
if (this.filepath.indexOf("/") === -1) {
this.filefolder = "";
}
- this.namespace = this.filefolder.replace(/\//g, ".").slice(0, -1);
+ this.namespace = this.filefolder.replace(/\//g, ".").replace(/^\.?(.*)\.$/g, "$1");
rgx = /^(class)+\s+([^\s]+)+(\s(extends)\s+([\w.]+))?/mg;
rgx_ext = /(^|=\s*)(class)\s(\w+)\s(extends)\s(\\w+)\s*$/gm;
if (this.raw.match(rgx) != null) {
@@ -1238,7 +1247,7 @@ var toaster = exports.toaster = {};
Builder.prototype.compile_for_debug = function() {
var absolute_path, file, files, folder_path, index, relative_path, release_path, _i, _len, _ref1;
- release_path = this.release.split("/").slice(0, -1).join("/");
+ release_path = this.debug.split("/").slice(0, -1).join("/");
release_path += "/toaster";
if (fs.existsSync(release_path)) {
FsUtil.rmdir_rf(release_path);
@@ -114,10 +114,16 @@ class FsUtil
onchange?( type:"file", path:filepath, action:"watching" )
- fs.watchFile filepath, {interval : 250}, (curr,prev)=>
+ fs.watchFile filepath, {persistent: true, interval : 30}, (curr,prev)=>
mtime = curr.mtime.valueOf() != prev.mtime.valueOf()
ctime = curr.ctime.valueOf() != prev.ctime.valueOf()
- if mtime || ctime
+
+ # file is deleted
+ if curr.nlink is 0
+ onchange?( {type: "file", path:filepath, action: "deleted"} )
+
+ # file is modified
+ else if mtime || ctime
onchange?( {type: "file", path:filepath, action: "updated"} )
@@ -188,7 +194,7 @@ class FsUtil
on_folder_change = FnUtil.proxy FsUtil._on_folder_change, folderpath
fs.unwatchFile folderpath
- fs.watchFile folderpath, {interval : 250}, on_folder_change
+ fs.watchFile folderpath, {persistent:true, interval : 30}, on_folder_change
@@ -204,16 +210,14 @@ class FsUtil
diff = ArrayUtil.diff a, b, "path"
# if there's no diff, abort the execution
- return unless diff.length
+ return unless diff.length
# saving watchers reference
watchers = FsUtil.watchers[folderpath]
# loop all diff itens
# ----------------------------------------------------------------------
for item in diff
- # console.log ".........."
- # console.log "ITEM..."
info = item.item
info.action = item.action
@@ -226,13 +230,11 @@ class FsUtil
# --------------------------------------------------------------
if info.type == "file"
- # console.log "FILE CREATED!"
# looping all watchers (listeners)
for watcher in watchers
# dispatch item if it passes the filter regexp
if watcher.filter.test info.path
- # console.log "ON CHANGE!"
watcher.onchange?( info )
FsUtil.watch_file info.path, watcher.onchange

0 comments on commit 7e069b7

Please sign in to comment.