Merge pull request #6 from coolbloke1324/master
Added a recursive chown to the methods
This commit is contained in:
commit
a087cb95d1
1 changed files with 27 additions and 0 deletions
|
|
@ -113,6 +113,33 @@ exports.chmodSyncRecursive = function(sourceDir, filemode) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* wrench.chownSyncRecursive("directory", uid, gid);
|
||||||
|
*
|
||||||
|
* Recursively dives through a directory and chowns everything to the desired user and group. This is a
|
||||||
|
* Synchronous function, which blocks things until it's done.
|
||||||
|
*
|
||||||
|
* Note: Directories should be passed to this function without a trailing slash.
|
||||||
|
*/
|
||||||
|
exports.chownSyncRecursive = function(sourceDir, uid, gid) {
|
||||||
|
var files = fs.readdirSync(sourceDir);
|
||||||
|
|
||||||
|
for(var i = 0; i < files.length; i++) {
|
||||||
|
var currFile = fs.statSync(sourceDir + "/" + files[i]);
|
||||||
|
|
||||||
|
if(currFile.isDirectory()) {
|
||||||
|
/* ...and recursion this thing right on back. */
|
||||||
|
exports.chownSyncRecursive(sourceDir + "/" + files[i], uid, gid);
|
||||||
|
} else {
|
||||||
|
/* At this point, we've hit a file actually worth chowning... so own it. */
|
||||||
|
fs.chownSync(sourceDir + "/" + files[i], uid, gid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finally, chown the parent directory */
|
||||||
|
fs.chownSync(sourceDir, uid, gid);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* wrench.rmdirRecursive("directory_path", callback);
|
/* wrench.rmdirRecursive("directory_path", callback);
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Reference in a new issue