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(()) | ||
| } No newline at end of file |
There was a problem hiding this comment.
This should probably be one op
There was a problem hiding this comment.
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.
@Im-Beast given that these basically call the same op, should this just be move?
There was a problem hiding this comment.
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.
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.
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.
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(()) | ||
| } No newline at end of file |
There was a problem hiding this comment.
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.
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.