Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uprefactor: ops/fs.rs should use tokio::fs where applicable #4188
Comments
|
I'm working on this issue now. Old version of op_realpath:
New version, passes tests:
Would like to refactor into a shorthand like this, but can't get it to work atm.
with a helper function in
|
|
@bartlomieju (cc @ry), In some cases we can move to a tokio version, but I'm not sure whether it's an improvement to do so. The existing implementation of
Possible downsides of that approach are: (1) it uses Here is a tokio-ized version of
The downsides of this implementation is that it requires a lot more syscalls, in order to be as robust as the previous version. (For example, if the attempt to apply a mode fails for some reason, we shouldn't leave a directory behind with different mode than requested. But if we did a recursive mkdir and the directory already existed, we shouldn't in that case try to apply the mode.) It may be useful to know that the Given that, what's your preference between these versions of Similar issues will apply to the op for |
|
I've got this issue 95% implemented now. There's a lot of subtleties, so it wouldn't have been such a great "first issue." :-) Am waiting feedback on what to do with mkdir and makeTempDir, and for some other PRs I've already pushed or have queued (related to #4017) to be merged, before pushing. |
|
@dubiousjim how many of ops from "fs" you could rewrite to Tokio version without problems described above? We could move gradually as |
|
@bartlomieju I was able to do all of them except the ones I mentioned (chown, utime, with mkdir/makeTemp up in the air). My ftruncate etc ops (still in the queue for #4017, waiting for other PRs to be merged first) use the nix crate, so they mostly don't have tokio correlates, so they're written instead like this:
I ended up doing a lot of refactoring of cli/fs.rs and cli/ops/fs.rs while doing this, but it was all worthwhile anyway. I'll push the refactoring + the tokio-izing soon (as either 1 or 2 PRs, I welcome input about which would be preferred). For mkdir, it's just up to you and/or @ry and/or other core devs which implementation you prefer. I have them both worked out. And once you've chosen for mkdir, I'll do makeTempDir on the same model. |
This helps refactoring, especially when std::fs calls are replaced with tokio::fs calls (denoland#4188)
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
This helps refactoring, especially when std::fs calls are replaced with tokio::fs calls (denoland#4188)
This a complex boring PR that shifts around code (primarily) in cli/fs.rs and cli/ops/fs.rs. The gain of this refactoring is to ease the way for #4188 and #4017, and also to avoid some future development pain. Mostly there is no change in functionality. Except: * squashed bugs where op_utime and op_chown weren't using `resolve_from_cwd` * eliminated the use of the external `remove_dir_all` crate. * op_chmod now only queries metadata to verify file/dir exists on Windows (it will already fail on Unix if it doesn't) * op_chown now verifies the file/dir's existence on Windows like chmod does.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.
|
It'd help to strategize together with some core devs more about this. As described above, I've already re-implemented most of The tokio-izing isn't straightforward. There are subtle differences in behavior and exceptional cases between While waiting for my queue of PRs to advance, I was looking ahead to what other file-system changes might be needed soon. I was interested in adding There's no technical obstacle to doing that, in lots of cases. The However, the strategy of (1) replacing I wanted to invite other dev's thoughts/feedback about this. |
When we shift from std::fs::read_dir to the tokio::fs version (denoland#4188), the processing of entries will be an async function, and Rust doesn't currently have a stable implementation of async closures. So instead of using `filter_map` with a closure, we iterate and build the Vec by hand. This makes the shift to tokio::fs more straightforward.


There are many functions available in
tokio::fsthat can be used to replace current blocking fs function used incli/ops/fs.rs.Example:
deno/cli/ops/fs.rs
Lines 189 to 214 in a29343c
It can be rewritten as follows:
Last bit could be factored out as
maybe_sync_opsimilar toblocking_json.This change should remove as many calls to as possible
blocking_json- it's better to use async functions where possible -spawn_blockingrequires separate threadpool for running blocking ops and we want to avoid that if possible.