-
Notifications
You must be signed in to change notification settings - Fork 407
Develop #322
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?
Develop #322
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,48 @@ | ||
| // write code here | ||
| /* eslint-disable no-console */ | ||
| 'use strict'; | ||
|
|
||
| const fsCb = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const [subject, destination] = process.argv.slice(2); | ||
|
|
||
| if (process.argv.slice(2).length !== 2) { | ||
| console.error('Usage: node index <source> <destination>'); | ||
|
|
||
| process.exit(0); | ||
|
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. All error exits in this file use |
||
| } | ||
|
|
||
| const fileName = path.basename(subject); | ||
| let destinationIsDirectory = false; | ||
|
|
||
| try { | ||
| destinationIsDirectory = fsCb.statSync(destination).isDirectory(); | ||
|
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 code does not handle the case where the destination ends with a slash (/) but does not exist. According to the requirements, if the destination is intended as a directory (ends with /) but does not exist, the app must throw an error and not create directories. Please add this check. |
||
| } catch (error) {} | ||
|
|
||
| const correctDestination = destinationIsDirectory | ||
| ? path.join(destination, fileName) | ||
| : destination; | ||
|
|
||
| if (!destinationIsDirectory && destination.endsWith(path.sep)) { | ||
| console.error('Destination must be correct path'); | ||
|
|
||
| process.exit(0); | ||
|
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. Same as above: this error exit should use |
||
| } | ||
|
|
||
| try { | ||
| fsCb.accessSync(subject, fsCb.constants.F_OK); | ||
|
|
||
| if (fsCb.statSync(subject).isDirectory()) { | ||
| console.error('Subject must be a file'); | ||
| process.exit(0); | ||
|
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. Same as above: this error exit should use |
||
| } | ||
| } catch (subError) { | ||
| console.error(`subject doesn't exist`); | ||
| process.exit(0); | ||
|
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. Same as above: this error exit should use |
||
| } | ||
|
|
||
| try { | ||
| fsCb.renameSync(subject, correctDestination); | ||
|
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 is no explicit check to ensure that only files are supported (not directories). The requirements specify that the app must not support moving directories. Please add a check to ensure the source is a file and not a directory, and throw an error otherwise. |
||
| } catch (err) { | ||
| console.error(err); | ||
|
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. Errors are only logged to the console, but the requirements specify that errors must be thrown and the process should indicate failure (e.g., exit with a non-zero code). Please update error handling to throw errors and exit with a non-zero code on failure. |
||
| } | ||
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.
There is no validation for the number of arguments. The requirements specify that you must verify exactly two arguments are provided (source and destination), and throw an error if not. Please add this validation.