refactor(rest) onFS delete: Util.call -> bind

This commit is contained in:
coderaiser 2014-02-06 03:49:53 -05:00
parent e0b56bc322
commit ebcaf450c5

View file

@ -204,8 +204,8 @@
case 'DELETE':
if (lQuery === 'dir')
fs.rmdir(p.name, function(pError) {
checkSendError(pError, params, function() {
fs.rmdir(p.name, function(error) {
checkSendError(error, params, function() {
sendMsg(params, 'delete', p.name);
});
});
@ -218,28 +218,19 @@
log = Util.log.bind(Util),
lAssync = 0;
function stat(pStat) {
var p, d,
ret = Util.checkObjTrue(pStat, 'params') &&
Util.checkObjTrue(pStat.params, 'name');
function onStat(name, error, stat) {
++lAssync;
if (ret) {
p = pStat,
d = p.params;
checkSendError(error, params, function() {
if (stat.isDirectory())
fs.rmdir(name, log);
++lAssync;
checkSendError(p.error, params, function() {
if (p.data.isDirectory())
fs.rmdir(d.name, log);
else if (p.data.isFile())
fs.unlink(d.name, log);
});
if (lAssync === n && !p.error)
sendMsg(params, 'delete', pBody);
}
else if (stat.isFile())
fs.unlink(name, log);
});
if (lAssync === n && !error)
sendMsg(params, 'delete', pBody);
}
for (i = 0; i < n; i ++) {
@ -247,9 +238,7 @@
Util.log(name);
fs.stat(name, Util.call(stat, {
name: name
}));
fs.stat(name, onStat.bind(null, name));
}
});
} else