Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added remove function to utils for removing directories recursively a…

…sync
  • Loading branch information...
commit 0c07c20fee8ef852c01ed07e87a8b2447ab52f06 1 parent 97c0837
Grigore Dutcovici authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/utils.js
38 lib/utils.js
View
@@ -315,6 +315,44 @@ module.exports = {
});
},
+ remove: function remove(path, callback) {
+ Fs.stat(path, function(error, stats) {
+ if (error) { return callback(error); }
+
+ if (stats.isFile()) {
+ Fs.unlink(path, function(error) {
+ return callback(error);
+ });
+ } else if (stats.isDirectory()) {
+ Fs.readdir(path, function(error, files) {
+ if (error) { return callback(error); }
+
+ var pending = files.length;
+
+ if (!pending) {
+ Fs.rmdir(path, function(error) {
+ callback(error);
+ });
+ }
+
+ files.forEach(function(file) {
+ remove(path +'/'+ file, function(error) {
+ if (error) {
+ return callback(error);
+ }
+
+ if (!--pending) {
+ Fs.rmdir(path, function(error) {
+ callback(error);
+ });
+ }
+ });
+ });
+ });
+ }
+ });
+ },
+
parse_cookies: function parse_cookies(cookie) {
var cookies = {};
Please sign in to comment.
Something went wrong with that request. Please try again.