Skip to content

Commit

Permalink
fix solution 3
Browse files Browse the repository at this point in the history
  • Loading branch information
denys-kononenko committed Feb 23, 2024
1 parent 63a2cd0 commit 039ea26
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/modules/customCopyFile.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/* eslint-disable no-console */
'use strict';

const fs = require('fs');
const path = require('path');

const customCopyFile = (sourceFile, destinationFile) => {
if (destinationFile === undefined) {
process.stderr.write('should be 2 params');
console.error('should be 2 params');

return;
}

if (sourceFile === destinationFile) {
return;
}

const sourcePath = path.join(__dirname, '..', '..', sourceFile);
const destinationPath = path.join(__dirname, '..', '..', destinationFile);

try {
fs.copyFileSync(sourcePath, destinationPath);
fs.copyFileSync(sourceFile, destinationFile);
} catch (err) {
if (err.code === 'EISDIR' || err.code === 'EPERM') {
process.stderr.write('source or destination is a directory');
}

if (err.code === 'ENOENT') {
process.stderr.write('non-existent source file');
}
console.error(err);
}
};

Expand Down

0 comments on commit 039ea26

Please sign in to comment.