Skip to content
Browse files

Move copy() worker under fstools.copy()

  • Loading branch information...
1 parent ec84563 commit d42df91f2e1482bc2e464561a6e48fda31a1c6e5 @ixti ixti committed
Showing with 29 additions and 37 deletions.
  1. +29 −37 lib/fs-tools.js
View
66 lib/fs-tools.js
@@ -99,8 +99,6 @@ function walk_recursive(path, iterator, callback) {
}
-var copy; // hack for lint :))
-
function copy_file(src, dst, callback) {
var ifd, ofd;
@@ -136,45 +134,12 @@ function copy_directory(src, dst, callback) {
}
walk_flat(src, function (sub_src, sub_stats, next) {
- copy(sub_src, dst + sub_src.replace(src, ''), sub_stats, next);
+ fstools.copy(sub_src, dst + sub_src.replace(src, ''), next);
}, callback);
});
}
-// copy src to dst recursively
-copy = function copy(src, dst, stats, callback) {
- var chmod, done;
-
- // chmod dst
- chmod = async.apply(fs.chmod, dst, stats.mode.toString(8).slice(-4));
-
- // reject async.series' results
- done = function (err, results) { callback(err); };
-
- // *** file
- if (stats.isFile()) {
- async.series([async.apply(copy_file, src, dst), chmod], done);
- return;
- }
-
- // *** symbolic link
- if (stats.isSymbolicLink()) {
- async.series([async.apply(copy_symlink, src, dst), chmod], done);
- return;
- }
-
- // *** directory
- if (stats.isDirectory()) {
- async.series([async.apply(copy_directory, src, dst), chmod], done);
- return;
- }
-
- // *** unsupported src
- callback(new Error("Unsupported type of the source"));
-};
-
-
// PUBLIC API
////////////////////////////////////////////////////////////////////////////////
@@ -463,12 +428,39 @@ fstools.copy = function (src, dst, callback) {
}
fstools.mkdir(dirname(dst), function (err) {
+ var chmod, done;
+
if (err) {
callback(err);
return;
}
- copy(src, dst, stats, callback);
+ // chmod dst
+ chmod = async.apply(fs.chmod, dst, stats.mode.toString(8).slice(-4));
+
+ // reject async.series' results
+ done = function (err, results) { callback(err); };
+
+ // *** file
+ if (stats.isFile()) {
+ async.series([async.apply(copy_file, src, dst), chmod], done);
+ return;
+ }
+
+ // *** symbolic link
+ if (stats.isSymbolicLink()) {
+ async.series([async.apply(copy_symlink, src, dst), chmod], done);
+ return;
+ }
+
+ // *** directory
+ if (stats.isDirectory()) {
+ async.series([async.apply(copy_directory, src, dst), chmod], done);
+ return;
+ }
+
+ // *** unsupported src
+ callback(new Error("Unsupported type of the source"));
});
});
};

0 comments on commit d42df91

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