-
Notifications
You must be signed in to change notification settings - Fork 5
Add file system functions #40
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: main
Are you sure you want to change the base?
Conversation
| #[op2(async)] | ||
| pub async fn op_move_file(#[string] origin: String, #[string] dest: String) -> Result<(), AnyError> { | ||
| tokio::fs::rename(origin, dest).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[op2(async)] | ||
| pub async fn op_move_folder(#[string] origin: String, #[string] dest: String) -> Result<(), AnyError> { | ||
| tokio::fs::rename(origin, dest).await?; | ||
| Ok(()) | ||
| } |
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.
This should probably be one op
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.
agreed, this could be just one op
| /** | ||
| * Moves file asyncrhonously | ||
| * @param {string} origin | ||
| * @param {string} dest | ||
| * @returns {Promise<void>} | ||
| */ | ||
| function moveFile(origin, dest) { | ||
| return core.ops.op_move_file(origin, dest); | ||
| } | ||
|
|
||
| /** | ||
| * Moves folder asyncrhonously | ||
| * @param {string} origin | ||
| * @param {string} dest | ||
| * @returns {Promise<void>} | ||
| */ | ||
| function moveFolder(origin, dest) { | ||
| return core.ops.op_move_folder(origin, dest); | ||
| } | ||
|
|
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.
@Im-Beast given that these basically call the same op, should this just be move?
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.
I agree, it doesn't make sense to have two different functions which do exactly the same thing.
I also wonder if rename is not a better name, since that's how std::fs method is named
| Ok(()) | ||
| } | ||
|
|
||
| use async_recursion::async_recursion; |
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.
please keep imports at the beggining of the file
|
|
||
| use async_recursion::async_recursion; | ||
| #[async_recursion] | ||
| pub async fn op_copy_dir_recurse(origin: String, dest: String) -> Result<(), AnyError> { |
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.
this is not really an op, prefix functions with op_ only when they use #[op]/#[op2] macros
| next.push_str(&itemStr); | ||
|
|
||
| // Recursive call to copy over contents of folder being looked at | ||
| op_copy_dir_recurse(entry.path().into_os_string().into_string().unwrap(), next).await?; |
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.
Please re-use wholePathStr here
| #[op2(async)] | ||
| pub async fn op_move_file(#[string] origin: String, #[string] dest: String) -> Result<(), AnyError> { | ||
| tokio::fs::rename(origin, dest).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[op2(async)] | ||
| pub async fn op_move_folder(#[string] origin: String, #[string] dest: String) -> Result<(), AnyError> { | ||
| tokio::fs::rename(origin, dest).await?; | ||
| Ok(()) | ||
| } |
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.
agreed, this could be just one op
| /** | ||
| * Moves file asyncrhonously | ||
| * @param {string} origin | ||
| * @param {string} dest | ||
| * @returns {Promise<void>} | ||
| */ | ||
| function moveFile(origin, dest) { | ||
| return core.ops.op_move_file(origin, dest); | ||
| } | ||
|
|
||
| /** | ||
| * Moves folder asyncrhonously | ||
| * @param {string} origin | ||
| * @param {string} dest | ||
| * @returns {Promise<void>} | ||
| */ | ||
| function moveFolder(origin, dest) { | ||
| return core.ops.op_move_folder(origin, dest); | ||
| } | ||
|
|
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.
I agree, it doesn't make sense to have two different functions which do exactly the same thing.
I also wonder if rename is not a better name, since that's how std::fs method is named
Copy folder implements async recursion which required the async recursion crate : https://crates.io/crates/async-recursion.