Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added rename

  • Loading branch information...
commit dcca394278fb7d4fd98099eb04aa6955806ea38c 1 parent 41ad33c
SkyArrow authored

Showing 1 changed file with 38 additions and 2 deletions. Show diff stats Hide diff stats

  1. +38 2 lib/qfs.js
40 lib/qfs.js
@@ -334,10 +334,31 @@ utils.each({
334 334 ],
335 335 rename: [
336 336 function(name, callback){
  337 + var arr = [],
  338 + fn = [];
  339 +
  340 + this.each(function(){
  341 + var _this = this;
337 342
  343 + fn.push(function(next){
  344 + fs.rename(_this.dir() + sep + name, next);
  345 + });
  346 + });
  347 +
  348 + async.parallel(fn, callback.bind(qfs(arr)));
  349 +
  350 + return this;
338 351 },
339 352 function(name){
  353 + var arr = [];
  354 +
  355 + this.each(function(){
  356 + var path = this.dir() + sep + name;
  357 + fs.renameSync(path);
  358 + arr.push(path);
  359 + });
340 360
  361 + return qfs(arr);
341 362 }
342 363 ],
343 364 remove: [
@@ -347,7 +368,16 @@ utils.each({
347 368 this.each(function(){
348 369 var path = this.path();
349 370 fn.push(function(next){
350   - fn.unlink(path, next);
  371 + this.stat(function(err, stat){
  372 + if (err) return callback(err);
  373 + if (stat.isFile()){
  374 + fs.unlink(path, next);
  375 + } else {
  376 + this.empty(function(){
  377 + fs.rmdir(path, next);
  378 + });
  379 + }
  380 + });
351 381 });
352 382 });
353 383
@@ -357,7 +387,13 @@ utils.each({
357 387 },
358 388 function(){
359 389 this.each(function(){
360   - fs.unlinkSync(this.path());
  390 + var stat = this.stat();
  391 + if (stat.isFile()){
  392 + fs.unlinkSync(this.path());
  393 + } else {
  394 + this.empty();
  395 + fs.rmdirSync(this.path());
  396 + }
361 397 });
362 398
363 399 return this;

0 comments on commit dcca394

Please sign in to comment.
Something went wrong with that request. Please try again.