-
Notifications
You must be signed in to change notification settings - Fork 407
task solution #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
task solution #324
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,65 @@ | ||
| // write code here | ||
| const fs = require('fs'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task requires using the promise-based |
||
| const path = require('path'); | ||
|
|
||
| function move() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good start on the Consider refactoring this function to be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To correctly use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you'll be using |
||
| if (process.argv.slice(2).length !== 2) { | ||
| // eslint-disable-next-line no-console | ||
| console.error( | ||
| 'Wrong number of arguments is supplied, should pass 2 arguments', | ||
| ); | ||
|
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the previous review, the application must |
||
|
|
||
| return; | ||
| } | ||
|
|
||
| const [sourceFile, destinationFile] = process.argv.slice(2); | ||
|
|
||
| if (!fs.existsSync(sourceFile)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a synchronous call. The requirements state that you must use the |
||
| // eslint-disable-next-line no-console | ||
| console.error('Non-existent source file'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task requires that an error must be thrown if the source file does not exist. Currently, you are logging a message to While this informs the user, it doesn't behave like a thrown error (e.g., it results in a successful process exit code |
||
|
|
||
| return; | ||
|
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The requirements state that your application must |
||
| } | ||
|
|
||
| const dirName = path.dirname(destinationFile); | ||
|
|
||
| if (!fs.existsSync(dirName)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check for the destination directory has a logical flaw. If You need a more robust way to validate the destination path. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two issues here. First, this is a synchronous call and should be replaced with an asynchronous one from |
||
| // eslint-disable-next-line no-console | ||
| console.error('Destination directory does not exist'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const normalizedSource = path.resolve(sourceFile); | ||
| const normalizedDest = path.resolve(destinationFile); | ||
|
|
||
| if (normalizedSource === normalizedDest) { | ||
| return; | ||
| } | ||
|
|
||
| if ( | ||
| fs.existsSync(normalizedDest) && | ||
| fs.statSync(normalizedDest).isDirectory() | ||
| ) { | ||
| const newFilePath = path.join(normalizedDest, path.basename(sourceFile)); | ||
|
|
||
| fs.renameSync(sourceFile, newFilePath); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most critical issue. The task requires the "move" operation to be implemented as a two-step process:
Using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the previous review, using You should implement this by:
|
||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (destinationFile.endsWith(path.sep)) { | ||
| const newFilePath = path.join(normalizedDest, path.basename(sourceFile)); | ||
|
|
||
| fs.renameSync(sourceFile, newFilePath); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| fs.renameSync(sourceFile, normalizedDest); | ||
|
Comment on lines
+45
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most critical part of the feedback. The task explicitly forbids using
Please replace all |
||
| } | ||
|
|
||
| move(); | ||
|
|
||
| module.exports = { | ||
| move, | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The task requires using the asynchronous
fs.promisesAPI for all file system operations. Please import it instead of the synchronousfsmodule. You can achieve this by changing this line toconst fs = require('fs').promises;.