-
Notifications
You must be signed in to change notification settings - Fork 439
Develop #361
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 #361
Changes from all commits
aaede61
ad52ae6
86ea0ee
dae0301
0f146b9
2aea9a2
91da2e4
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 |
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,72 @@ | ||
| // write code here | ||
| /* eslint-disable no-console */ | ||
|
|
||
| // something new x2 | ||
|
|
||
| function main() { | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| if (process.argv.slice(2).length !== 2) { | ||
| console.error('Usage: node app.js <file> <newFile>'); | ||
| // throw new Error('Usage: node app.js <file> <newFile>'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const [file, newFile] = process.argv.slice(2); | ||
|
|
||
| if (!fs.existsSync(file)) { | ||
| console.error(`${file} doesn't exist`); | ||
| // throw new Error(`${file} doesn't exist`); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| const srcStats = fs.statSync(file); | ||
|
|
||
| if (!srcStats.isFile()) { | ||
| console.error(`${file} must be a File`); | ||
| // throw new Error(`${file} must be a File`); | ||
|
|
||
| return; | ||
|
Comment on lines
+27
to
+31
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. You already call
Comment on lines
+27
to
+31
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. When the source exists but is not a regular file you currently |
||
| } | ||
|
|
||
| const destExists = fs.existsSync(newFile); | ||
| const stats = destExists ? fs.statSync(newFile) : null; | ||
| const fileName = path.basename(file); | ||
| const parentDir = path.dirname(newFile); | ||
|
|
||
| if (newFile.endsWith('/')) { | ||
| if (!destExists) { | ||
| console.error(`${newFile} doesn't exist`); | ||
| // throw new Error(`${newFile} doesn't exist`); | ||
|
|
||
| return; | ||
|
Comment on lines
+39
to
+44
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. When the destination ends with
Comment on lines
+40
to
+44
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. When |
||
| } | ||
|
|
||
| const newPath = path.join(newFile, fileName); | ||
|
|
||
| fs.renameSync(file, newPath); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (stats && stats.isDirectory()) { | ||
| const newPath = path.join(newFile, fileName); | ||
|
|
||
| fs.renameSync(file, newPath); | ||
|
Comment on lines
+54
to
+57
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. Inside the |
||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (!fs.existsSync(parentDir)) { | ||
| console.error(`Invalid destination path: ${newFile}`); | ||
| // throw new Error(`Invalid destination path: ${newFile}`); | ||
|
|
||
| return; | ||
|
Comment on lines
+62
to
+66
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.
Comment on lines
+62
to
+66
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. When validating the parent directory of the destination you currently |
||
| } | ||
|
|
||
| fs.renameSync(file, newFile); | ||
| } | ||
|
|
||
| main(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Adulescens cultura defetiscor creptio vestigium velociter dolore. Voveo balbus territo vallum dicta tunc. Celo capio cunctatio undique carmen surgo. | ||
| Fugit pectus trucido suus. Cibo votum turba astrum animi angelus copia auditor aut. Tristis nostrum defluo audax substantia. | ||
| Vulariter adsum condico corona strenuus ceno cauda arx vallum consuasor. Barba confugo rem cornu barba sonitus corpus. Sordeo constans appello clarus desipio tepidus commodo altus incidunt voluptatum. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Vesper bene totam angustus aestas. Tracto theologus pecco harum ipsa. Voluptates volo arx. | ||
| Capillus molestiae abeo. Tui via curis. Ars corrumpo acceptus curia suffoco praesentium abeo. | ||
| Decumbo concido demo absorbeo quidem corrumpo eveniet magnam crebro. Adinventitias cultura utique absens tardus confido asper recusandae. Circumvenio viscus vere deleo barba nulla ventus vetus. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Veritatis totidem cruentus crinis turba acies cubicularis amplus excepturi. Absque repudiandae thorax maiores ipsum. Facere atqui adimpleo artificiose crebro constans. | ||
| Defetiscor talus sperno tristis vesco adeptio summisse aperio. Arbor tolero sopor supellex adipisci nemo cado. Casus adeptio contra tondeo conservo collum in catena. | ||
| Dolorem terga auctor desparatus universe succurro umbra sortitus. Balbus valeo animi rerum carcer teres patria alo spiculum. Tendo cohors tribuo trans. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Combibo taceo dedecor ager a civitas. Crastinus facilis balbus valde coerceo vicissitudo bonus varius viscus. Caveo temptatio vae rerum aestivus denuo decipio tempora deleo. | ||
| Angelus vulpes alveus tandem allatus carpo. Curia odit comparo audeo comburo adulescens vita aut. Appello uxor odio demulceo apto ciminatio admoveo. | ||
| Spoliatio tergum cenaculum cunabula subito alioqui vespillo teneo amissio. Possimus venustas tametsi copiose crux spero. Verto ipsum aeger. |
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 code checks that the source path exists but does not verify that the source is a file (not a directory). The task requires the app to support only moving of files, so add a check such as
fs.statSync(file).isFile()and error out if it's not a regular file.