Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit 4a789c4

Browse files
author
Lucas Rojas
committed
Clean comments in filetools.js
1 parent e164286 commit 4a789c4

File tree

1 file changed

+0
-25
lines changed

1 file changed

+0
-25
lines changed

lib/fileTools.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ function copyFolder (source, target, options, callback) {
7777
}
7878

7979
return Q.nfcall(ncp, source, target, options || {}).catch(function (err) {
80-
// flatten errors, otherwise it breaks things downstream
81-
// see https://github.com/AvianFlu/ncp/issues/52
8280
if (Array.isArray(err)) {
8381
var msg = err.reduce(function (previous, current) {
8482
return previous += (previous.length ? '\n' : '') + current.message;
@@ -101,11 +99,9 @@ function replaceFileContent (source, replacementFunc, callback) {
10199
}
102100

103101
function mkdirp (filePath, callback) {
104-
// ensure filePath points to a valid drive
105102
var fullPath = path.resolve(filePath);
106103
var rootPath = path.parse(fullPath).root;
107104

108-
// create directory recursively
109105
return stat(rootPath).then(function () {
110106
return Q.nfcall(_mkdirp, filePath);
111107
})
@@ -154,40 +150,30 @@ function searchFile (dir, fileName, callback) {
154150
});
155151
}
156152

157-
// Copies the 'source' file to 'target' if it's missing after creating the
158-
// required directory structure.
159153
function syncFile (source, target, callback) {
160154

161-
// check target file
162155
return stat(target).then(function (info) {
163-
// verify that target is a file and not a directory
164156
if (info.isDirectory()) {
165157
return Q.reject(new Error('Cannot synchronize file \'' + source + '\'. There is already a directory in the target with the same name.'));
166158
}
167159

168-
// skip target if it already exists
169160
return;
170161
})
171162
.catch(function (err) {
172-
// return failure for anything other than 'not found'
173163
if (err.code !== 'ENOENT') {
174164
return Q.reject(err);
175165
}
176166

177-
// copy source to target
178167
var targetDir = path.dirname(target);
179168
return stat(targetDir).catch(function (err) {
180-
// return failure for anything other than 'not found'
181169
if (err.code !== 'ENOENT') {
182170
return Q.reject(err);
183171
}
184172

185-
// create target directory
186173
return mkdirp(targetDir).then(function () {
187174
log.debug('Created target directory at \'' + targetDir + '\'.');
188175
})
189176
.catch(function (err) {
190-
// ignore error if target was already created by a different "thread"
191177
if (err.code !== 'EEXIST') {
192178
return Q.reject(err);
193179
}
@@ -221,37 +207,30 @@ function syncFiles (source, target, options, callback) {
221207
options = {};
222208
}
223209

224-
// read the contents of the source directory
225210
return Q.nfcall(fs.readdir, source).then(function (files) {
226211

227-
// process each file and folder
228212
var tasks = files.map(function (fileOrDir) {
229213
var sourceFile = path.join(source, fileOrDir);
230214
return stat(sourceFile).then(function (info) {
231215

232-
// if fileOrDir is a directory, synchronize it
233216
if (info.isDirectory()) {
234217
return syncFiles(sourceFile, path.join(target, fileOrDir), options);
235218
}
236219

237-
// check to see if file should be skipped
238220
if (options.filter) {
239221
var check = options.filter(fileOrDir);
240222
if (check === false) {
241223
return;
242224
}
243225
}
244226

245-
// synchronize a single file
246227
var targetFile = path.join(target, fileOrDir);
247228
return syncFile(sourceFile, targetFile);
248229
});
249230
});
250231

251-
// wait for all pending tasks to complete
252232
return Q.all(tasks).then(function (values) {
253233

254-
// build a list of the files that were copied
255234
return values.reduce(function (list, value) {
256235
if (value) {
257236
if (Array.isArray(value)) {
@@ -271,17 +250,13 @@ function syncFiles (source, target, options, callback) {
271250
return Q.reject(err);
272251
}
273252

274-
// specified source is a file not a directory
275253
var sourceFile = path.basename(source);
276254
var targetFile = path.basename(target);
277255

278-
// build target file path assuming target is a directory
279-
// unless target already includes the file name
280256
if (sourceFile !== targetFile) {
281257
target = path.join(target, sourceFile);
282258
}
283259

284-
// synchronize the file
285260
return syncFile(source, target).then(function (file) {
286261
return file ? [file] : [];
287262
});

0 commit comments

Comments
 (0)