From 4bbf8e905988fbc9874548af663d24a876cc5823 Mon Sep 17 00:00:00 2001 From: Artur Shatskov Date: Sun, 11 Jan 2026 20:32:09 +0100 Subject: [PATCH 1/2] Solution --- src/app.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/app.js b/src/app.js index ad9a93a..cb73ca3 100644 --- a/src/app.js +++ b/src/app.js @@ -1 +1,37 @@ +/* eslint-disable no-console */ 'use strict'; + +const [source, dest] = process.argv.slice(2); +const fs = require('fs'); +const path = require('path'); + +if (!source || !dest) { + console.error('Missing source or destination file path.'); + process.exit(1); +} + +const sourcePath = path.resolve(source); +const destPath = path.resolve(dest); + +if (!fs.existsSync(sourcePath)) { + console.error(`Source file does not exist: ${sourcePath}`); + process.exit(1); +} + +if (fs.statSync(sourcePath).isDirectory()) { + console.error(`Source must be a file, not a directory: ${sourcePath}`); + process.exit(1); +} + +if (fs.existsSync(destPath) && fs.statSync(destPath).isDirectory()) { + console.error(`Destination must be a file, not a directory: ${destPath}`); + process.exit(1); +} + +fs.copyFile(sourcePath, destPath, (err) => { + if (err) { + console.error(`Error copying file from ${sourcePath} to ${destPath}:`, err); + process.exit(1); + } + console.log(`File copied from ${sourcePath} to ${destPath} successfully.`); +}); From d9b517cf220b380350a667b99edc17743a89d6d5 Mon Sep 17 00:00:00 2001 From: Artur Shatskov Date: Sun, 11 Jan 2026 20:44:10 +0100 Subject: [PATCH 2/2] Solution2 --- src/app.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app.js b/src/app.js index cb73ca3..33c2436 100644 --- a/src/app.js +++ b/src/app.js @@ -7,31 +7,35 @@ const path = require('path'); if (!source || !dest) { console.error('Missing source or destination file path.'); - process.exit(1); + process.exit(0); } const sourcePath = path.resolve(source); const destPath = path.resolve(dest); +if (sourcePath === destPath) { + process.exit(0); +} + if (!fs.existsSync(sourcePath)) { console.error(`Source file does not exist: ${sourcePath}`); - process.exit(1); + process.exit(0); } if (fs.statSync(sourcePath).isDirectory()) { - console.error(`Source must be a file, not a directory: ${sourcePath}`); - process.exit(1); + console.error(`Source file is a directory: ${sourcePath}`); + process.exit(0); } if (fs.existsSync(destPath) && fs.statSync(destPath).isDirectory()) { - console.error(`Destination must be a file, not a directory: ${destPath}`); - process.exit(1); + console.error(`Destination file is a directory: ${destPath}`); + process.exit(0); } fs.copyFile(sourcePath, destPath, (err) => { if (err) { console.error(`Error copying file from ${sourcePath} to ${destPath}:`, err); - process.exit(1); + process.exit(0); } console.log(`File copied from ${sourcePath} to ${destPath} successfully.`); });