-
Notifications
You must be signed in to change notification settings - Fork 131
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
Refactor fs.rs to use call_with_permit scheme #741
Refactor fs.rs to use call_with_permit scheme #741
Conversation
38aed41
to
2702336
Compare
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.
Reviewed 7 of 7 files at r1, all commit messages.
Reviewable status: 0 of 1 LGTMs obtained
-- commits
line 2 at r1:
nit: Would be nice to have a bit more information (just like one or two sentences) in the body of the commit message.
nativelink-util/src/fs.rs
line 285 at r1 (raw file):
Ok(res) => res, Err(_) => Err(make_err!(Code::Internal, "background task failed")), }
Suggestion:
tokio::task::spawn_blocking(move || f(permit))
.await
.unwrap_or_else(|e| Err(make_err!(Code::Internal, "background task failed: {e:?}")))
nativelink-util/src/fs.rs
line 434 at r1 (raw file):
} pub async fn rename(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<(), Error> {
nit: I really appreciate these simplifications. Something I noticed is that I think we could change all the function signatures to use PathBuf
like so:
pub async fn rename(from: PathBuf, to: PathBuf) -> Result<(), Error> {
call_with_permit(move |_| std::fs::rename(from, to).map_err(Into::into)).await
}
I played around with this a bit and it seems like using PathBuf
instead of all the manual Cow
and OsStr
also makes the filesystem store much easier on the eyes.
nativelink-util/src/fs.rs
line 437 at r1 (raw file):
let from = from.as_ref().to_owned(); let to = to.as_ref().to_owned(); call_with_permit(move |_| std::fs::rename(from, to).map_err(|e| e.into())).await
nit: You could change all the |e| e.into()
to Into::into
or Into::<Error>::into
.
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.
Reviewable status: 1 of 1 LGTMs obtained
Simplify filesystem functions by delegating permit acquisition and execution to a single callback
2702336
to
53afa6a
Compare
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.
Reviewable status: 1 of 1 LGTMs obtained, and pending CI: Analyze (javascript-typescript), Bazel Dev / ubuntu-22.04, Local / ubuntu-22.04, Vercel, asan / ubuntu-22.04, docker-compose-compiles-nativelink (20.04), pre-commit-checks, publish-image, ubuntu-20.04 / stable, ubuntu-22.04, vale
nativelink-util/src/fs.rs
line 285 at r1 (raw file):
Ok(res) => res, Err(_) => Err(make_err!(Code::Internal, "background task failed")), }
I like this as well
nativelink-util/src/fs.rs
line 434 at r1 (raw file):
Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…
nit: I really appreciate these simplifications. Something I noticed is that I think we could change all the function signatures to use
PathBuf
like so:pub async fn rename(from: PathBuf, to: PathBuf) -> Result<(), Error> { call_with_permit(move |_| std::fs::rename(from, to).map_err(Into::into)).await }
I played around with this a bit and it seems like using
PathBuf
instead of all the manualCow
andOsStr
also makes the filesystem store much easier on the eyes.
Changing the signature here breaks types in a couple other places. I'm happy to make the changes but not sure if I should in this PR since this is a backport of other code that was already shipped. Let me know your thoughts
nativelink-util/src/fs.rs
line 437 at r1 (raw file):
Previously, aaronmondal (Aaron Siddhartha Mondal) wrote…
nit: You could change all the
|e| e.into()
toInto::into
orInto::<Error>::into
.
Into::<Error>::into
seems a bit clearer as to what's going on so I'll go with that
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.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: 2 of 1 LGTMs obtained
nativelink-util/src/fs.rs
line 434 at r1 (raw file):
Previously, zbirenbaum (Zach Birenbaum) wrote…
Changing the signature here breaks types in a couple other places. I'm happy to make the changes but not sure if I should in this PR since this is a backport of other code that was already shipped. Let me know your thoughts
Yeah, I'd use PathBuf
when all possible. Cow
is just to remove the need for a copy when able, but PathBuf
can suffice in many/all cases.
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.
Reviewed all commit messages.
Reviewable status: 2 of 1 LGTMs obtained
nativelink-util/src/fs.rs
line 434 at r1 (raw file):
Previously, allada (Nathan (Blaise) Bruer) wrote…
Yeah, I'd use
PathBuf
when all possible.Cow
is just to remove the need for a copy when able, butPathBuf
can suffice in many/all cases.
Let's defer these signature changes to another PR.
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.
FYI @zbirenbaum You'll need to click the "resolve" and "acknowledge buttons in Reviewable, that'll unblock this PR for merging.
Reviewable status: 2 of 1 LGTMs obtained
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.
Reviewed all commit messages.
Reviewable status:complete! 3 of 1 LGTMs obtained
Description
Refactor fs.rs to use call_with_permit scheme
Checklist
bazel test //...
passes locallygit amend
see some docsThis change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)