Block `tokio::fs` symbols (#15374)

Inspired by #15017, mirror the blocking of `std::fs` symbols in favor of
`fs_err` and block `tokio::fs` symbols in favor of `fs_err::tokio`.
This commit is contained in:
konsti 2025-08-19 13:13:46 +02:00 committed by GitHub
parent f98cb7dece
commit 7a9e07a98e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 2 deletions

View File

@ -17,6 +17,11 @@ disallowed-types = [
"std::fs::File",
"std::fs::OpenOptions",
"std::fs::ReadDir",
"tokio::fs::DirBuilder",
"tokio::fs::DirEntry",
"tokio::fs::File",
"tokio::fs::OpenOptions",
"tokio::fs::ReadDir",
]
disallowed-methods = [
@ -38,7 +43,28 @@ disallowed-methods = [
"std::fs::soft_link",
"std::fs::symlink_metadata",
"std::fs::write",
"tokio::fs::canonicalize",
"tokio::fs::copy",
"tokio::fs::create_dir",
"tokio::fs::create_dir_all",
"tokio::fs::hard_link",
"tokio::fs::metadata",
"tokio::fs::read",
"tokio::fs::read_dir",
"tokio::fs::read_link",
"tokio::fs::read_to_string",
"tokio::fs::remove_dir",
"tokio::fs::remove_dir_all",
"tokio::fs::remove_file",
"tokio::fs::rename",
"tokio::fs::set_permissions",
"tokio::fs::symlink_metadata",
"tokio::fs::try_exists",
"tokio::fs::write",
{ path = "std::os::unix::fs::symlink", allow-invalid = true },
{ path = "std::os::windows::fs::symlink_dir", allow-invalid = true },
{ path = "std::os::windows::fs::symlink_file", allow-invalid = true },
{ path = "tokio::fs::symlink", allow-invalid = true },
{ path = "tokio::fs::symlink_dir", allow-invalid = true },
{ path = "tokio::fs::symlink_file", allow-invalid = true },
]

View File

@ -733,7 +733,10 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
// Download the wheel to a temporary file.
let temp_file = tempfile::tempfile_in(self.build_context.cache().root())
.map_err(Error::CacheWrite)?;
let mut writer = tokio::io::BufWriter::new(tokio::fs::File::from_std(temp_file));
let mut writer = tokio::io::BufWriter::new(fs_err::tokio::File::from_std(
// It's an unnamed file on Linux so that's the best approximation.
fs_err::File::from_parts(temp_file, self.build_context.cache().root()),
));
match progress {
Some((reporter, progress)) => {

View File

@ -1799,7 +1799,7 @@ pub async fn download_to_disk(url: &str, path: &Path) {
.await
.unwrap();
let mut file = tokio::fs::File::create(path).await.unwrap();
let mut file = fs_err::tokio::File::create(path).await.unwrap();
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.next().await {
file.write_all(&chunk.unwrap()).await.unwrap();