removed previous function
fixed docs
This commit is contained in:
parent
02bd67c8a6
commit
fee7f769ae
1 changed files with 7 additions and 56 deletions
|
|
@ -317,6 +317,13 @@ exports.rmdirRecursive = function rmdirRecursive(dir, failSilent, clbk){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* wrench.copyDirRecursive("directory_to_copy", "new_location", {preserve: bool, inflateSymlinks:bool, excludeHiddenUnix:bool }, callback);
|
||||||
|
*
|
||||||
|
* Recursively dives through a directory and moves all its files to a new
|
||||||
|
* location.
|
||||||
|
*
|
||||||
|
* Note: Directories should be passed to this function without a trailing slash.
|
||||||
|
*/
|
||||||
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
|
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
|
||||||
|
|
||||||
if (typeof opts === 'function')
|
if (typeof opts === 'function')
|
||||||
|
|
@ -389,62 +396,6 @@ exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/* wrench.copyDirRecursive("directory_to_copy", "new_location", {forceDelete: bool}, callback);
|
|
||||||
*
|
|
||||||
* Recursively dives through a directory and moves all its files to a new
|
|
||||||
* location. Specify forceDelete to force directory overwrite.
|
|
||||||
*
|
|
||||||
* Note: Directories should be passed to this function without a trailing slash.
|
|
||||||
*/
|
|
||||||
exports.copyDirRecursive = function copyDirRecursive(srcDir, newDir, opts, clbk) {
|
|
||||||
fs.stat(newDir, function(err, newDirStat){
|
|
||||||
if(!err) {
|
|
||||||
if(typeof opts !== 'undefined' && typeof opts !== 'function' && opts.forceDelete)
|
|
||||||
return exports.rmdirRecursive(newDir, function(err){
|
|
||||||
copyDirRecursive.apply(this, arguments);
|
|
||||||
});
|
|
||||||
else
|
|
||||||
return clbk(new Error('You are trying to delete a directory that already exists. Specify forceDelete in an options object to override this.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof opts === 'function')
|
|
||||||
clbk = opts;
|
|
||||||
|
|
||||||
fs.stat(srcDir, function(err, srcDirStat){
|
|
||||||
if (err) return clbk(err);
|
|
||||||
fs.mkdir(newDir, srcDirStat.mode, function(err){
|
|
||||||
if (err) return clbk(err);
|
|
||||||
fs.readdir(srcDir, function(err, files){
|
|
||||||
if (err) return clbk(err);
|
|
||||||
(function copyFiles(err){
|
|
||||||
if (err) return clbk(err);
|
|
||||||
|
|
||||||
var filename = files.shift();
|
|
||||||
if (filename === null || typeof filename == 'undefined')
|
|
||||||
return clbk(null);
|
|
||||||
|
|
||||||
var file = srcDir+'/'+filename,
|
|
||||||
newFile = newDir+'/'+filename;
|
|
||||||
|
|
||||||
fs.stat(file, function(err, fileStat){
|
|
||||||
if (fileStat.isDirectory())
|
|
||||||
copyDirRecursive(file, newFile, copyFiles);
|
|
||||||
else if (fileStat.isSymbolicLink())
|
|
||||||
fs.readlink(file, function(err, link){
|
|
||||||
fs.symlink(link, newFile, copyFiles);
|
|
||||||
});
|
|
||||||
else
|
|
||||||
fs.readFile(file, function(err, data){
|
|
||||||
fs.writeFile(newFile, data, copyFiles);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
var mkdirSyncRecursive = function(path, mode) {
|
var mkdirSyncRecursive = function(path, mode) {
|
||||||
var self = this;
|
var self = this;
|
||||||
path = _path.normalize(path)
|
path = _path.normalize(path)
|
||||||
|
|
|
||||||
Reference in a new issue