-
Notifications
You must be signed in to change notification settings - Fork 407
Solution #328
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?
Solution #328
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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ master ] | ||
|
|
||
| jobs: | ||
| build: | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| matrix: | ||
| node-version: [20.x] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
| - run: npm install | ||
| - run: npm test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| erfer |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,44 @@ | ||
| // write code here | ||
| /* eslint-disable no-console */ | ||
|
|
||
| const { rename } = require('fs/promises'); | ||
| const { statSync, existsSync } = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| async function app() { | ||
| const args = process.argv.slice(2); | ||
| const [source, destination] = args; | ||
|
|
||
| if (!source || !destination) { | ||
| console.error(`Two arguments was needed`); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (existsSync(source) && !statSync(source).isFile()) { | ||
| console.error(`I can move just files! `); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const slicedDest = destination.endsWith('/') | ||
| ? destination.slice(0, -1) | ||
| : destination; | ||
|
|
||
| try { | ||
| const isDestDir = | ||
| existsSync(slicedDest) && statSync(slicedDest).isDirectory(); | ||
|
|
||
| const finDest = isDestDir | ||
| ? path.join(slicedDest, path.basename(source)) | ||
| : slicedDest; | ||
|
Comment on lines
+23
to
+33
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 logic block doesn't correctly handle a key requirement: when the destination path ends with a Currently, if You'll need to add a specific check before this
Author
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. try { } catch (e) { |
||
|
|
||
| await rename(source, finDest); | ||
| console.log(`${source} was moved to ${destination}`); | ||
| } catch (e) { | ||
| console.error(`The file could not be moved. Error: ${e}`); | ||
| } | ||
|
Comment on lines
+23
to
+39
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 logic still doesn't meet the requirement for handling destination paths that end with a Currently, if the destination is You need to add a specific check before this |
||
| } | ||
|
|
||
| app(); | ||
|
|
||
| module.exports = { app }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Vel odio sequi caput cernuus temperantia. Vulnus tabella callide acceptus teres xiphias. Arma desolo quam tubineus bos cupiditas pecco decor confugo. | ||
| Vomer caute cado audentia perspiciatis conicio vulticulus abundans atavus civis. Patior volo comedo vigilo cohaero cubo dolorem. Ipsa esse adhuc. | ||
| Accusator vesper nihil turba subito tredecim quibusdam curiositas. Dapifer textor aufero aliquam adamo casus deserunt charisma depereo decens. Accommodo viscus vigor adduco. |
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 requirements state that the app must only support moving files. You should add a check here to verify that the
sourcepath points to a file and not a directory. Consider usingstatSync(source).isFile()before attempting to move it.