1 |
|
2 | var fs = require('fs'),
|
3 | path = require('path');
|
4 | var readdirr = require('./readdirr').readdirr;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | exports.cpdirr = function (spath, tpath, cb) {
|
17 | readdirr(spath, function (err, dirs, files) {
|
18 | if (err) return cb(err);
|
19 | exports.cpdirs(spath, tpath, dirs, function (err) {
|
20 | if (err) return cb(err);
|
21 | exports.cpfiles(spath, tpath, files, function (err) {
|
22 | if (err) return cb(err);
|
23 | cb();
|
24 | });
|
25 | });
|
26 | });
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | exports.cpdirs = function (spath, tpath, dirs, cb) {
|
40 | dirs.sort();
|
41 | (function loop (index) {
|
42 | if (index == dirs.length) return cb();
|
43 | var rpath = path.relative(spath, dirs[index]);
|
44 | rpath = path.join(tpath, rpath);
|
45 | fs.exists(rpath, function (exists) {
|
46 | if (exists) return loop(++index);
|
47 | fs.mkdir(rpath, function (err) {
|
48 | if (err) return cb(err);
|
49 | loop(++index);
|
50 | });
|
51 | });
|
52 | }(0));
|
53 | }
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | exports.cpfiles = function (spath, tpath, files, cb) {
|
66 | (function loop (index) {
|
67 | if (index == files.length) return cb();
|
68 | fs.readFile(files[index], function (err, data) {
|
69 | if (err) return cb(err);
|
70 | var rpath = path.relative(spath, files[index]);
|
71 | rpath = path.join(tpath, rpath);
|
72 | fs.writeFile(rpath, data, function (err) {
|
73 | if (err) return cb(err);
|
74 | loop(++index);
|
75 | });
|
76 | });
|
77 | }(0));
|
78 | }
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|