feature(dir) add isDir

This commit is contained in:
coderaiser 2014-03-05 06:42:27 -05:00
parent 09a1c7169e
commit 1c1c933a21
4 changed files with 28 additions and 19 deletions

View file

@ -17,6 +17,7 @@
AppCache = main.appcache,
Util = main.util,
update = main.update,
dir = main.dir,
server = main.librequire('server'),
Minify = main.minify,
@ -250,9 +251,8 @@
}
function getContent(name, callback) {
fs.stat(name, function(error, stat) {
dir.isDir(name, function(error, isDir) {
var getDirContent = main.commander.getDirContent,
isDir = stat && stat.isDirectory(),
func = Util.retExec(callback);
if (!error && isDir)

View file

@ -20,17 +20,15 @@
checkParams = main.checkCallBackParams;
exports.getDirContent = function(path, callback) {
var ret = Util.isString(path);
var isString = Util.isString(path);
if (!ret)
if (!isString)
Util.exec(callback, "First parameter should be a string");
else
fs.readdir(path, readDir.bind(null, {
callback : callback,
path : path
}));
return ret;
};

View file

@ -19,6 +19,19 @@
Util = main.util,
path = main.path;
exports.isDir = function(name, callback) {
name += '';
fs.stat(name, function(error, stat) {
var isDir;
if (!error)
isDir = stat.isDirectory();
Util.exec(callback, error, isDir);
});
};
exports.getSize = function(dir, callback) {
var total = 0;

View file

@ -141,7 +141,7 @@
else {
p.name += '.json';
str = Util.stringifyJSON(data);
sendResponse(p, str);
sendResponse(p, str, true);
}
});
@ -246,7 +246,7 @@
}
function onDelete(name, files, query, callback) {
var i, n, onStat,
var i, n, onStat, isDirFunc,
assync = 0,
rmFile = fs.unlink.bind(fs),
rmDir = fse.remove.bind(fse),
@ -265,17 +265,16 @@
n = files && files.length,
dir = name;
onStat = function(name, error, stat) {
onIsDir = function(name, error, isDir) {
var log = Util.log.bind(Util);
++assync;
if (error)
func(error);
else {
if (stat.isDirectory())
if (isDir)
rmDir(name, log);
else if (stat.isFile())
else
rmFile(name, log);
if (assync === n)
@ -284,9 +283,11 @@
};
for (i = 0; i < n; i ++) {
name = dir + files[i];
name = dir + files[i];
isDirFunc = Util.bind(onIsDir, name);
dir.isDir(name, isDirFunc);
Util.log(name);
fs.stat(name, onStat.bind(null, name));
}
break;
}
@ -340,9 +341,8 @@
break;
default:
fs.stat(name, function(error, stat) {
var getDirContent = main.commander.getDirContent,
isDir = stat && stat.isDirectory();
dir.isDir(name, function(error, isDir) {
var getDirContent = main.commander.getDirContent;
if (isDir && !error)
getDirContent(name, func);
@ -398,8 +398,6 @@
lCmd = p.command,
lFiles = Util.parseJSON(p.body);
console.log(lFiles);
switch(lCmd) {
case 'auth':
main.auth(p.body, function(pTocken) {