Skip to content
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

use fs_err for sake of better io errors #1616

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ directories = "4.0.1"
env_logger = "0.10"
filetime = "0.2"
flate2 = { version = "1.0", optional = true, default-features = false, features = ["rust_backend"] }
fs-err = "2.9"
futures = "0.3"
gzp = { version = "0.11.1", default-features = false, features = ["deflate_rust"] }
http = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sccache-dist/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

use anyhow::{anyhow, bail, Context, Error, Result};
use flate2::read::GzDecoder;
use fs_err as fs;
use libmount::Overlay;
use sccache::dist::{
BuildResult, BuilderIncoming, CompileCommand, InputsReader, OutputData, ProcessOutput, TcCache,
Toolchain,
};
use sccache::lru_disk_cache::Error as LruError;
use std::collections::{hash_map, HashMap};
use std::fs;
use std::io;
use std::iter;
use std::path::{self, Path, PathBuf};
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use crate::config::Config;
feature = "webdav"
))]
use crate::config::{self, CacheType};
use fs_err as fs;
use std::fmt;
use std::fs;
use std::io::{self, Cursor, Read, Seek, Write};
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down
3 changes: 2 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ use crate::server::{self, DistInfo, ServerInfo, ServerStartup};
use crate::util::daemonize;
use atty::Stream;
use byteorder::{BigEndian, ByteOrder};
use fs::{File, OpenOptions};
use fs_err as fs;
use log::Level::Trace;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{File, OpenOptions};
use std::io::{self, Write};
#[cfg(unix)]
use std::os::unix::process::ExitStatusExt;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ use crate::dist;
use crate::dist::pkg;
use crate::mock_command::CommandCreatorSync;
use crate::util::{hash_all, Digest, HashToDigest};
use fs_err as fs;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::fs;
use std::hash::Hash;
#[cfg(feature = "dist-client")]
use std::io;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use crate::compiler::{gcc, write_temp_file, Cacheable, CompileCommand, CompilerA
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use fs::File;
use fs_err as fs;
use semver::{BuildMetadata, Prerelease, Version};
use std::ffi::OsString;
use std::fs::File;
use std::future::Future;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use crate::lru_disk_cache;
use crate::mock_command::{exit_status, CommandChild, CommandCreatorSync, RunCommand};
use crate::util::{fmt_duration_as_secs, ref_env, run_input_output};
use filetime::FileTime;
use fs::File;
#[cfg(feature = "dist-client")]
use fs_err as fs;
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::fmt;
#[cfg(feature = "dist-client")]
use std::fs;
use std::fs::File;
use std::future::Future;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -1231,7 +1231,7 @@ mod test {
use crate::mock_command::*;
use crate::test::mock_storage::MockStorage;
use crate::test::utils::*;
use std::fs::{self, File};
use fs::File;
use std::io::Write;
use std::sync::Arc;
use std::time::Duration;
Expand Down
8 changes: 5 additions & 3 deletions src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ use crate::errors::*;
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use fs::File;
use fs_err as fs;
use log::Level::Trace;
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::process;
Expand Down Expand Up @@ -435,13 +436,14 @@ impl<'a> Iterator for ExpandAtArgs<'a> {
#[cfg(test)]
mod test {
use super::{
dist, generate_compile_commands, parse_arguments, Language, OsString, ParsedArguments, ARGS,
dist, fs, generate_compile_commands, parse_arguments, Language, OsString, ParsedArguments,
ARGS,
};
use crate::compiler::c::ArtifactDescriptor;
use crate::compiler::*;
use crate::mock_command::*;
use crate::test::utils::*;
use std::fs::File;
use fs::File;
use std::io::Write;

fn parse_arguments_(arguments: Vec<String>) -> CompilerArguments<ParsedArguments> {
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ use crate::compiler::{clang, Cacheable, ColorMode, CompileCommand, CompilerArgum
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use fs::File;
use fs_err as fs;
use log::Level::Trace;
use std::collections::HashMap;
use std::ffi::OsString;
use std::fs::File;
use std::io::Read;
use std::path::{Path, PathBuf};
use std::process;
Expand Down Expand Up @@ -871,7 +872,7 @@ impl<'a> Iterator for ExpandIncludeFile<'a> {

#[cfg(test)]
mod test {
use std::fs::File;
use fs::File;
use std::io::Write;

use super::*;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use crate::compiler::{
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::run_input_output;
use crate::{counted_array, dist};
use fs::File;
use fs_err as fs;
use log::Level::Debug;
use std::collections::{HashMap, HashSet};
use std::ffi::{OsStr, OsString};
use std::fs::File;
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Stdio};
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ use crate::compiler::{gcc, write_temp_file, Cacheable, CompileCommand, CompilerA
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use fs::File;
use fs_err as fs;
use log::Level::Trace;
use std::ffi::OsString;
use std::fs::File;
use std::future::Future;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::util::{fmt_duration_as_secs, hash_all, hash_all_archives, run_input_o
use crate::util::{ref_env, HashToDigest, OsStrExt};
use crate::{counted_array, dist};
use filetime::FileTime;
use fs_err as fs;
use log::Level::Trace;
#[cfg(feature = "dist-client")]
#[cfg(feature = "dist-client")]
Expand All @@ -42,7 +43,6 @@ use std::env::consts::DLL_EXTENSION;
use std::env::consts::{DLL_PREFIX, EXE_EXTENSION};
use std::ffi::OsString;
use std::fmt;
use std::fs;
use std::future::Future;
use std::hash::Hash;
#[cfg(feature = "dist-client")]
Expand Down Expand Up @@ -280,7 +280,7 @@ where
T: AsRef<Path>,
U: AsRef<Path>,
{
let mut f = fs::File::open(file)?;
let mut f = fs::File::open(file.as_ref())?;
let mut deps = String::new();
f.read_to_string(&mut deps)?;
Ok((parse_dep_info(&deps, cwd), parse_env_dep_info(&deps)))
Expand Down Expand Up @@ -2405,9 +2405,9 @@ mod test {
use crate::compiler::*;
use crate::mock_command::*;
use crate::test::utils::*;
use fs::File;
use itertools::Itertools;
use std::ffi::OsStr;
use std::fs::File;
use std::io::{self, Write};
use std::sync::{Arc, Mutex};

Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

use directories::ProjectDirs;
use fs::File;
use fs_err as fs;
use regex::Regex;
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
Expand All @@ -22,7 +24,6 @@ use serde::ser::{Serialize, Serializer};
use serial_test::serial;
use std::collections::HashMap;
use std::env;
use std::fs::{self, File};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
use std::result::Result as StdResult;
Expand Down
8 changes: 4 additions & 4 deletions src/dist/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::dist::Toolchain;
use crate::lru_disk_cache::Result as LruResult;
use crate::lru_disk_cache::{LruDiskCache, ReadSeek};
use anyhow::{anyhow, Result};
use std::fs;
use fs_err as fs;
use std::io;
use std::path::{Path, PathBuf};

Expand All @@ -18,8 +18,8 @@ mod client {
use crate::dist::Toolchain;
use crate::lru_disk_cache::Error as LruError;
use anyhow::{bail, Context, Error, Result};
use fs_err as fs;
use std::collections::{HashMap, HashSet};
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
Expand Down Expand Up @@ -214,7 +214,7 @@ mod client {
debug!("Weak key {} appears to be new", weak_key);
let tmpfile = tempfile::NamedTempFile::new_in(self.cache_dir.join("toolchain_tmp"))?;
toolchain_packager
.write_pkg(tmpfile.reopen()?)
.write_pkg(fs_err::File::from_parts(tmpfile.reopen()?, tmpfile.path()))
.context("Could not package toolchain")?;
let tc = cache.insert_file(tmpfile.path())?;
self.record_weak(weak_key.to_owned(), tc.archive_id.clone())?;
Expand Down Expand Up @@ -304,7 +304,7 @@ mod client {
}
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
impl crate::dist::pkg::ToolchainPackager for PanicToolchainPackager {
fn write_pkg(self: Box<Self>, _f: ::std::fs::File) -> crate::errors::Result<()> {
fn write_pkg(self: Box<Self>, _f: super::fs::File) -> crate::errors::Result<()> {
panic!("should not have called packager")
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dist/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ mod client {
Ok(Some(toolchain_file)) => {
let url = urls::server_submit_toolchain(job_alloc.server_id, job_alloc.job_id);
let req = self.client.lock().unwrap().post(url);
let toolchain_file = tokio::fs::File::from_std(toolchain_file);
let toolchain_file = tokio::fs::File::from_std(toolchain_file.into());
let toolchain_file_stream = tokio_util::io::ReaderStream::new(toolchain_file);
let body = Body::wrap_stream(toolchain_file_stream);
let req = req.bearer_auth(job_alloc.auth).body(body);
Expand Down
8 changes: 4 additions & 4 deletions src/dist/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use crate::dist;
use std::fs;
use fs_err as fs;
use std::io;
use std::path::{Component, Path, PathBuf};
use std::str;
Expand All @@ -38,7 +38,7 @@ pub trait OutputsRepackager {
#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
mod toolchain_imp {
use super::ToolchainPackager;
use std::fs;
use fs_err as fs;

use crate::errors::*;

Expand All @@ -54,8 +54,8 @@ mod toolchain_imp {
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
mod toolchain_imp {
use super::tarify_path;
use fs_err as fs;
use std::collections::BTreeMap;
use std::fs;
use std::io::{Read, Write};
use std::path::{Component, Path, PathBuf};
use std::process;
Expand Down Expand Up @@ -176,7 +176,7 @@ mod toolchain_imp {
}
for (tar_path, file_path) in file_set.into_iter() {
let file = &mut fs::File::open(file_path)?;
builder.append_file(tar_path, file)?
builder.append_file(tar_path, file.file_mut())?
}
builder.finish().map_err(Into::into)
}
Expand Down
5 changes: 3 additions & 2 deletions src/lru_disk_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
pub mod lru_cache;

use fs::File;
use fs_err as fs;
use std::borrow::Borrow;
use std::boxed::Box;
use std::collections::hash_map::RandomState;
use std::error::Error as StdError;
use std::ffi::{OsStr, OsString};
use std::fmt;
use std::fs::{self, File};
use std::hash::BuildHasher;
use std::io;
use std::io::prelude::*;
Expand Down Expand Up @@ -315,10 +316,10 @@ impl LruDiskCache {

#[cfg(test)]
mod tests {
use super::fs::{self, File};
use super::{Error, LruDiskCache};

use filetime::{set_file_times, FileTime};
use std::fs::{self, File};
use std::io::{self, Read, Write};
use std::path::{Path, PathBuf};
use tempfile::TempDir;
Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ use crate::util;
use anyhow::Context as _;
use bytes::{buf::BufMut, Bytes, BytesMut};
use filetime::FileTime;
use fs::metadata;
use fs_err as fs;
use futures::channel::mpsc;
use futures::future::FutureExt;
use futures::{future, stream, Sink, SinkExt, Stream, StreamExt, TryFutureExt};
use number_prefix::NumberPrefix;
use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::metadata;
use std::future::Future;
use std::io::{self, Write};
use std::marker::Unpin;
Expand Down Expand Up @@ -114,7 +115,7 @@ fn notify_server_startup(name: &Option<OsString>, status: ServerStartup) -> Resu

#[cfg(windows)]
fn notify_server_startup(name: &Option<OsString>, status: ServerStartup) -> Result<()> {
use std::fs::OpenOptions;
use fs::OpenOptions;

let name = match *name {
Some(ref s) => s,
Expand Down
3 changes: 2 additions & 1 deletion src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use crate::jobserver::Client;
use crate::mock_command::*;
use crate::server::{DistClientContainer, SccacheServer, ServerMessage};
use crate::test::utils::*;
use fs::File;
use fs_err as fs;
use futures::channel::oneshot::{self, Sender};
#[cfg(not(target_os = "macos"))]
use serial_test::serial;
use std::fs::File;
use std::io::{Cursor, Write};
#[cfg(not(target_os = "macos"))]
use std::net::TcpListener;
Expand Down
Loading