-
Notifications
You must be signed in to change notification settings - Fork 407
Завдання Move files #323
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?
Завдання Move files #323
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,35 @@ | ||
| /* eslint-disable no-console */ | ||
| // write code here | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const moveFiles = () => { | ||
| const args = process.argv.slice(2); | ||
|
|
||
| const [fileName, newPath] = args; | ||
|
|
||
| if (args.length < 2) { | ||
| console.error('You need fileName and destination'); | ||
|
|
||
| return; | ||
| } | ||
|
Comment on lines
+11
to
+15
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. Argument count enforcement — must accept exactly two positional arguments. Current code uses
Comment on lines
+7
to
+15
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. Silent acceptance of extra arguments — must reject extras. The program destructures only two arguments and ignores the rest. The checker may pass extra args to validate strict parsing. Enforce |
||
|
|
||
| try { | ||
| const isDirectory = | ||
| fs.existsSync(newPath) && fs.lstatSync(newPath).isDirectory(); | ||
|
|
||
| const updatedPath = isDirectory | ||
| ? path.join(newPath, path.basename(fileName)) | ||
| : newPath; | ||
|
Comment on lines
+17
to
+23
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. Destination trailing-slash semantics and directory existence check. Right now
Comment on lines
+17
to
+23
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. Behavior for The task states: if |
||
|
|
||
| fs.renameSync(fileName, updatedPath); | ||
|
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. Single
|
||
| } catch (error) { | ||
| console.error('Error occurred:', error); | ||
| } | ||
|
Comment on lines
+26
to
+28
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. Error handling: logged errors don't cause non-zero exit. The
Comment on lines
+11
to
+28
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. Improve error messages and early exits for CLI clarity. Instead of generic messages like |
||
| }; | ||
|
|
||
| moveFiles(); | ||
|
|
||
| module.exports = { | ||
| moveFiles, | ||
| }; | ||
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.
Missing source validation — must verify source exists and is a regular file.
You destructure
fileNamefrom args but never check that the path exists or is a file. The spec requires that moving directories is not supported and that missing sources produce an error. Add aconst stat = fs.lstatSync(fileName)and checkstat.isFile(). If it doesn't exist or!isFile, print an error andprocess.exit(1). This addresses: "The source must be a file; moving directories is not supported". (lines 6-10)