WebAssemblyOS / wasmos

OS primitives and shell for AssembyScript and WebAssembly
MIT License
40 stars 21 forks source link

working on mv command #118

Open VDozorov opened 5 years ago

VDozorov commented 5 years ago

fixes #117

willemneal commented 5 years ago

If you now do a pull from this branch you'll get the files that I added, packages/ash/assembly/bin/mv.ts and packages/ash/assembly/__tests__/mv.spec.ts

This is a copy of cp.ts, which is a good starting place. You'll need to use fs.delete and fs.deleteDirectory. For now just moving files will suffice so you'll really just need to use fs.delete.

VDozorov commented 5 years ago

What are the cases (if any) where fs.delete(*source file*) can fail?

Edit: it fails when what's in parenthesis isn't a file and is a file directory, in which case fs.deleteDirectory should be used

VDozorov commented 5 years ago

"There was a compilation error when trying to create the wasm binary for file: packages/ash/assembly/tests/mv.spec.ts."

This problem only exists when I have my lines added in trying to delete the source file. I've looked at trying to close the file before deleting it but all the syntax is still a little confusing. Is there something else I need to do or is just closing the source file and deleting it fine?

VDozorov commented 5 years ago

Thought I should do a try-catch block to see if fs.delete fails due to being passed a directory but apparently try-catch isn't supported. How can I test if what's given is a file or directory? Just look at the end of the string?

willemneal commented 5 years ago

You have openFile and openDirectory, openFile will return a WasiResult that fails if the path provided points to a directory and vice versa.

VDozorov commented 5 years ago

But that doesn't seem to be the case with the example 'cp' code, it only used openFile

willemneal commented 5 years ago

From above > "For now just moving files will suffice so you'll really just need to use fs.delete." So you only need fs.openFile.