Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.
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 @@ -40,6 +40,7 @@ filetime = "0.2"
flate2 = { version = "1.0", optional = true, default-features = false, features = ["rust_backend"] }
futures = "0.3"
futures-locks = "0.6"
fs-err = "2.6"
hmac = { version = "0.10", optional = true }
http = "0.2"
hyper = { version = "0.13", optional = true }
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 @@ -20,8 +20,8 @@ use sccache::dist::{
Toolchain,
};
use sccache::lru_disk_cache::Error as LruError;
use sccache::util::fs;
use std::collections::{hash_map, HashMap};
use std::fs;
use std::io;
use std::iter;
use std::path::{self, Path, PathBuf};
Expand Down
6 changes: 3 additions & 3 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ use crate::cache::redis::RedisCache;
#[cfg(feature = "s3")]
use crate::cache::s3::S3Cache;
use crate::config::{self, CacheType, Config};
use std::fmt;
use std::fs;
use crate::util::fs;
#[cfg(feature = "gcs")]
use std::fs::File;
use crate::util::fs::File;
use std::fmt;
use std::io::{self, Cursor, Read, Seek, Write};
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use crate::mock_command::{CommandChild, CommandCreatorSync, ProcessCommandCreato
use crate::protocol::{Compile, CompileFinished, CompileResponse, Request, Response};
use crate::server::{self, DistInfo, ServerInfo, ServerStartup};
use crate::util::daemonize;
use crate::util::fs::{File, OpenOptions};
use atty::Stream;
use byteorder::{BigEndian, ByteOrder};
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 @@ -22,12 +22,12 @@ use crate::dist;
#[cfg(feature = "dist-client")]
use crate::dist::pkg;
use crate::mock_command::CommandCreatorSync;
use crate::util::fs;
use crate::util::{hash_all, Digest, HashToDigest};
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
1 change: 0 additions & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::dist;
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
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 @@ -26,15 +26,15 @@ use crate::dist;
use crate::dist::pkg;
use crate::lru_disk_cache;
use crate::mock_command::{exit_status, CommandChild, CommandCreatorSync, RunCommand};
#[cfg(feature = "dist-client")]
use crate::util::fs;
use crate::util::fs::File;
use crate::util::{fmt_duration_as_secs, ref_env, run_input_output};
use filetime::FileTime;
use std::borrow::Cow;
use std::collections::HashMap;
use std::ffi::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 @@ -1148,7 +1148,7 @@ mod test {
use crate::mock_command::*;
use crate::test::mock_storage::MockStorage;
use crate::test::utils::*;
use std::fs::{self, File};
use crate::util::fs::{self, File};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be in favour of never using File but always stick to fs::File everywhere. There are almost no files with more than 2 occurences of File.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a code style issue (arguments go both ways) and I'd rather avoid the churn of making changes for the sake of it. Let's keep the diff to a minimum and focus on the easily swapping out std::fs for better errors, which is the reason for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point.

use std::io::Write;
use std::sync::Arc;
use std::time::Duration;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use crate::compiler::{Cacheable, ColorMode, CompileCommand, CompilerArguments};
use crate::dist;
use crate::errors::*;
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::fs::File;
use crate::util::{run_input_output, OsStrExt};
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 @@ -424,7 +424,7 @@ mod test {
use crate::compiler::*;
use crate::mock_command::*;
use crate::test::utils::*;
use std::fs::File;
use crate::util::fs::File;
use std::io::Write;

fn parse_arguments_(arguments: Vec<String>) -> CompilerArguments<ParsedArguments> {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use crate::compiler::c::{CCompilerImpl, CCompilerKind, Language, ParsedArguments
use crate::compiler::{clang, Cacheable, ColorMode, CompileCommand, CompilerArguments};
use crate::dist;
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::fs::File;
use crate::util::{run_input_output, OsStrExt};
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 @@ -732,7 +732,6 @@ impl<'a> Iterator for ExpandIncludeFile<'a> {

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

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::compiler::{
};
use crate::dist;
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::fs::File;
use crate::util::run_input_output;
use local_encoding::{Encoder, Encoding};
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
1 change: 0 additions & 1 deletion src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
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 @@ -25,6 +25,7 @@ use crate::dist::pkg;
#[cfg(feature = "dist-client")]
use crate::lru_disk_cache::{LruCache, Meter};
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::fs;
use crate::util::{fmt_duration_as_secs, hash_all, run_input_output, Digest};
use crate::util::{ref_env, HashToDigest, OsStrExt};
use filetime::FileTime;
Expand All @@ -41,7 +42,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 @@ -294,7 +294,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))
Expand Down Expand Up @@ -2302,9 +2302,9 @@ mod test {
use crate::compiler::*;
use crate::mock_command::*;
use crate::test::utils::*;
use crate::util::fs::File;
use itertools::Itertools;
use std::ffi::OsStr;
use std::fs::File;
use std::io::Write;
use std::sync::{Arc, Mutex};

Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::util::fs::{self, File};
use directories::ProjectDirs;
use regex::Regex;
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
Expand All @@ -20,7 +21,6 @@ use serde::de::{Deserialize, DeserializeOwned, Deserializer};
use serde::ser::{Serialize, Serializer};
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
12 changes: 8 additions & 4 deletions src/dist/cache.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::dist::Toolchain;
use crate::lru_disk_cache::Result as LruResult;
use crate::lru_disk_cache::{LruDiskCache, ReadSeek};
use crate::util::fs;
use anyhow::{anyhow, Result};
use std::fs;
use std::io;
use std::path::{Path, PathBuf};

Expand All @@ -17,9 +17,9 @@ mod client {
use crate::dist::pkg::ToolchainPackager;
use crate::dist::Toolchain;
use crate::lru_disk_cache::Error as LruError;
use crate::util::fs;
use anyhow::{bail, Context, Error, Result};
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 @@ -202,7 +202,11 @@ 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(
tmpfile
.reopen()
.map(|file| fs::File::from_parts(file, 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 @@ -292,7 +296,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: crate::util::fs::File) -> crate::errors::Result<()> {
panic!("should not have called packager")
}
}
Expand Down
10 changes: 5 additions & 5 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 crate::util::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 crate::util::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 crate::util::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 @@ -169,8 +169,8 @@ mod toolchain_imp {
builder.append_dir(tar_path, dir_path)?
}
for (tar_path, file_path) in file_set.into_iter() {
let file = &mut fs::File::open(file_path)?;
builder.append_file(tar_path, file)?
let mut file = fs::File::open(file_path)?;
builder.append_file(tar_path, file.file_mut())?
}
builder.finish().map_err(Into::into)
}
Expand Down
4 changes: 2 additions & 2 deletions src/lru_disk_cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub mod lru_cache;

use crate::util::fs::{self, File};
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 @@ -317,8 +317,8 @@ impl LruDiskCache {
mod tests {
use super::{Error, LruDiskCache};

use crate::util::fs::{self, File};
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
4 changes: 2 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::jobserver::Client;
use crate::mock_command::{CommandCreatorSync, ProcessCommandCreator};
use crate::protocol::{Compile, CompileFinished, CompileResponse, Request, Response};
use crate::util;
use crate::util::fs::metadata;
#[cfg(feature = "dist-client")]
use anyhow::Context as _;
use bytes::{buf::ext::BufMutExt, Bytes, BytesMut};
Expand All @@ -37,7 +38,6 @@ 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 +114,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 crate::util::fs::OpenOptions;

let name = match *name {
Some(ref s) => s,
Expand Down
2 changes: 1 addition & 1 deletion src/simples3/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! Types for loading and managing AWS access credentials for API requests.
#![allow(dead_code)]

use crate::util::fs::{self, File};
use chrono::{offset, DateTime, Duration};
use directories::UserDirs;
use futures::future;
Expand All @@ -12,7 +13,6 @@ use reqwest::Client;
use std::ascii::AsciiExt;
use std::collections::HashMap;
use std::env::*;
use std::fs::{self, File};
use std::future::Future;
use std::io::prelude::*;
use std::io::BufReader;
Expand Down
2 changes: 1 addition & 1 deletion src/test/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::jobserver::Client;
use crate::mock_command::*;
use crate::server::{DistClientContainer, SccacheServer, ServerMessage};
use crate::test::utils::*;
use crate::util::fs::File;
use futures::channel::oneshot::{self, Sender};
use std::fs::File;
use std::io::{Cursor, Write};
#[cfg(not(target_os = "macos"))]
use std::net::TcpListener;
Expand Down
Loading