Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/cache/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn get_packages_timeout() -> u64 {

/// Try to get where the rv cache dir should be
pub fn get_user_cache_dir() -> Option<PathBuf> {
if let Some(p) = std::env::var(crate::consts::CACHE_DIR_ENV_VAR_NAME).ok() {
if let Ok(p) = std::env::var(crate::consts::CACHE_DIR_ENV_VAR_NAME) {
return Some(PathBuf::from(p));
}

Expand Down
8 changes: 4 additions & 4 deletions src/cli/commands/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ impl TreeNode<'_> {
max_depth: Option<usize>,
show_sys_deps: bool,
) {
if let Some(d) = max_depth {
if current_depth > d {
return;
}
if let Some(d) = max_depth
&& current_depth > d
{
return;
}

println!(
Expand Down
9 changes: 2 additions & 7 deletions src/cli/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ use crate::{Resolution, Resolver};

use crate::{GitExecutor, Http};

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum ResolveMode {
#[default]
Default,
FullUpgrade,
// TODO: PartialUpgrade -- allow user to specify packages to upgrade
}

impl Default for ResolveMode {
fn default() -> Self {
ResolveMode::Default
}
}

/// Resolve dependencies for the project. If there are any unmet dependencies, they will be printed
/// to stderr and the cli will exit.
pub fn resolve_dependencies<'a>(
Expand Down
8 changes: 4 additions & 4 deletions src/cli/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl SyncHelper {
) -> Result<Resolution<'a>> {
// TODO: exit on failure without println? and move that to main.rs
// otherwise callers will think everything is fine
let resolution = resolve_dependencies(&context, &resolve_mode, self.exit_on_failure);
let resolution = resolve_dependencies(context, &resolve_mode, self.exit_on_failure);

match timeit!(
if self.dry_run {
Expand All @@ -70,7 +70,7 @@ impl SyncHelper {
&context.library,
&context.cache,
&context.system_dependencies,
&context.config.configure_args(),
context.config.configure_args(),
&context.cache.system_info,
self.save_install_logs_in.clone(),
context.staging_path(),
Expand Down Expand Up @@ -122,11 +122,11 @@ impl SyncHelper {
}

if let Some(log_folder) = &self.save_install_logs_in {
fs::create_dir_all(&log_folder)?;
fs::create_dir_all(log_folder)?;
for change in changes.iter().filter(|x| x.installed) {
let log_path = change.log_path(&context.cache);
if log_path.exists() {
fs::copy(log_path, log_folder.join(&format!("{}.log", change.name)))?;
fs::copy(log_path, log_folder.join(format!("{}.log", change.name)))?;
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ impl<'de> Deserialize<'de> for HttpUrl {
D: Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
if s.starts_with("http://") || s.starts_with("https://") {
if let Ok(mut url) = Url::parse(&s) {
// Remove trailing slashes from the path
let path = url.path().trim_end_matches('/').to_string();
url.set_path(&path);
return Ok(Self(url));
}
if (s.starts_with("http://") || s.starts_with("https://"))
&& let Ok(mut url) = Url::parse(&s)
{
// Remove trailing slashes from the path
let path = url.path().trim_end_matches('/').to_string();
url.set_path(&path);
return Ok(Self(url));
}

Err(serde::de::Error::custom("Invalid URL"))
Expand Down Expand Up @@ -220,14 +220,14 @@ pub enum OsTarget {
}

impl OsTarget {
fn matches(&self, system_info: &crate::system_info::SystemInfo) -> bool {
fn matches(&self, system_info: &SystemInfo) -> bool {
use crate::system_info::OsType;
match (&system_info.os_type, self) {
(OsType::Linux(_), OsTarget::Linux) => true,
(OsType::MacOs, OsTarget::Macos) => true,
(OsType::Windows, OsTarget::Windows) => true,
_ => false,
}
matches!(
(&system_info.os_type, self),
(OsType::Linux(_), OsTarget::Linux)
| (OsType::MacOs, OsTarget::Macos)
| (OsType::Windows, OsTarget::Windows)
)
}
}

Expand All @@ -245,13 +245,13 @@ pub enum ArchTarget {
impl ArchTarget {
fn matches(&self, system_info: &SystemInfo) -> bool {
let current_arch = system_info.arch().unwrap_or("unknown");
match (current_arch, self) {
("x86_64" | "amd64", ArchTarget::X86_64) => true,
("aarch64" | "arm64", ArchTarget::Arm64) => true,
("x86" | "i386" | "i686", ArchTarget::X86) => true,
("arm" | "armv7", ArchTarget::Arm) => true,
_ => false,
}
matches!(
(current_arch, self),
("x86_64" | "amd64", ArchTarget::X86_64)
| ("aarch64" | "arm64", ArchTarget::Arm64)
| ("x86" | "i386" | "i686", ArchTarget::X86)
| ("arm" | "armv7", ArchTarget::Arm)
)
}
}

Expand Down
12 changes: 1 addition & 11 deletions src/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn update_repository(
}

// Create the updated repository
let parsed_url = Url::parse(&new_url).map_err(|e| ConfigureErrorKind::InvalidUrl(e))?;
let parsed_url = Url::parse(&new_url).map_err(ConfigureErrorKind::InvalidUrl)?;
let new_repo = create_repository_value(&new_alias, &parsed_url, new_force_source);
repos.replace(index, new_repo);

Expand Down Expand Up @@ -863,16 +863,6 @@ dependencies = [
// This should work (updating to the same alias)
execute_repository_action(&config_path, action).unwrap();

// Now try with a different existing alias - this should fail
let action = RepositoryAction::Update {
matcher: RepositoryMatcher::ByAlias("posit".to_string()),
updates: RepositoryUpdates {
alias: Some("posit".to_string()), // Wait, we need another repo first
url: None,
force_source: None,
},
};

// First, let's add another repository so we can test duplicate error
let add_action = RepositoryAction::Add {
alias: "cran".to_string(),
Expand Down
12 changes: 4 additions & 8 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn copy_folder_parallel(
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
.map_err(std::io::Error::other)?;

let from = from.as_ref();
let to = to.as_ref();
Expand Down Expand Up @@ -206,7 +206,7 @@ pub(crate) fn untar_archive<R: Read>(
Ok(temp_dir) => {
let tar = GzDecoder::new(buffer.as_slice());
let mut archive = Archive::new(tar);
if let Ok(_) = archive.unpack(temp_dir.path()) {
if archive.unpack(temp_dir.path()).is_ok() {
// Count files to determine if we should use parallel copy
let file_count = WalkDir::new(temp_dir.path())
.into_iter()
Expand Down Expand Up @@ -259,10 +259,7 @@ pub(crate) fn untar_archive<R: Read>(
}
}
_ => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"not tar.gz or a .zip archive",
));
return Err(std::io::Error::other("not tar.gz or a .zip archive"));
}
}

Expand All @@ -283,8 +280,7 @@ pub(crate) fn untar_archive<R: Read>(
#[cfg(target_os = "linux")]
pub(crate) fn is_nfs(path: impl AsRef<Path>) -> Result<bool, std::io::Error> {
use nix::sys::statfs::{NFS_SUPER_MAGIC, statfs};
let st =
statfs(path.as_ref()).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
let st = statfs(path.as_ref()).map_err(std::io::Error::other)?;

Ok(st.filesystem_type() == NFS_SUPER_MAGIC)
}
Expand Down
72 changes: 24 additions & 48 deletions src/git/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,21 @@ impl GitRepository {
// Before fetching, checks whether the oid exists locally
// We only do that for commits since tag/branches could have changed remotely
// so finding a reference locally is not meaningful
if let GitReference::Commit(c) = reference {
if let Some(oid) = self.ref_as_oid(c) {
if self
.executor
.execute(
Command::new("git")
.arg("cat-file")
.arg("-e")
.arg(oid.as_str())
.current_dir(&self.path),
)
.is_ok()
{
log::debug!(
"No need to fetch {url}, reference {reference:?} is already found locally"
);
return Ok(());
}
}
if let GitReference::Commit(c) = reference
&& let Some(oid) = self.ref_as_oid(c)
&& self
.executor
.execute(
Command::new("git")
.arg("cat-file")
.arg("-e")
.arg(oid.as_str())
.current_dir(&self.path),
)
.is_ok()
{
log::debug!("No need to fetch {url}, reference {reference:?} is already found locally");
return Ok(());
}

log::debug!("Fetching {url} with reference {reference:?}");
Expand Down Expand Up @@ -174,12 +170,7 @@ impl GitRepository {
.arg(oid.as_str())
.current_dir(&self.path),
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to checkout `{}`", oid.as_str()),
)
})?;
.map_err(|_| std::io::Error::other(format!("Failed to checkout `{}`", oid.as_str())))?;

self.update_submodules()?;
Ok(())
Expand All @@ -200,10 +191,7 @@ impl GitRepository {
.current_dir(&self.path),
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to checkout branch `{branch_name}`"),
)
std::io::Error::other(format!("Failed to checkout branch `{branch_name}`"))
})?;

self.update_submodules()?;
Expand All @@ -228,10 +216,9 @@ impl GitRepository {
}

if branch_name.is_empty() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("No HEAD branch found, output of CLI was:\n{output}\n"),
));
return Err(std::io::Error::other(format!(
"No HEAD branch found, output of CLI was:\n{output}\n"
)));
}

self.checkout_branch(&branch_name)
Expand Down Expand Up @@ -328,12 +315,7 @@ impl GitRepository {
.arg(reference)
.current_dir(&self.path),
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Reference {} not found", &reference),
)
})?;
.map_err(|_| std::io::Error::other(format!("Reference {} not found", &reference)))?;
Ok(Oid::new(output))
}

Expand All @@ -356,12 +338,7 @@ impl GitRepository {
.arg("--recursive")
.current_dir(&self.path),
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to update submodules".to_string(),
)
})?;
.map_err(|_| std::io::Error::other("Failed to update submodules".to_string()))?;
Ok(())
}

Expand Down Expand Up @@ -458,7 +435,6 @@ mod tests {
use super::*;
use crate::git::GitExecutor;
use std::process::Command;
use tempfile;

fn run_git(args: &[&str], dir: &Path) {
let output = Command::new("git")
Expand Down Expand Up @@ -495,8 +471,8 @@ mod tests {
run_git(&["commit", "-m", "initial"], &work_path);

let branch_name = "main";
run_git(&["checkout", "-b", &branch_name], &work_path);
run_git(&["push", "origin", &branch_name], &work_path);
run_git(&["checkout", "-b", branch_name], &work_path);
run_git(&["push", "origin", branch_name], &work_path);

(temp_dir, branch_name.to_string())
}
Expand Down
5 changes: 1 addition & 4 deletions src/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ impl CommandExecutor for GitExecutor {
if res.status.success() {
Ok(String::from_utf8_lossy(&res.stdout).trim().to_string())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
String::from_utf8_lossy(&res.stderr),
))
Err(std::io::Error::other(String::from_utf8_lossy(&res.stderr)))
}
}
}
8 changes: 4 additions & 4 deletions src/git/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ impl GitRemote {
if let Some(o) = repo.ref_as_oid(reference.reference()) {
repo.checkout(&o)?;
} else {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to find reference {:?}", reference),
));
return Err(std::io::Error::other(format!(
"Failed to find reference {:?}",
reference
)));
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/git/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl TryFrom<&str> for GitUrl {
}

// Try to parse as a standard URL
if s2.starts_with("http://") || s2.starts_with("https://") {
if let Ok(url) = Url::parse(s2) {
return Ok(GitUrl::Http(url));
}
if (s2.starts_with("http://") || s2.starts_with("https://"))
&& let Ok(url) = Url::parse(s2)
{
return Ok(GitUrl::Http(url));
}

Err(format!("Invalid URL format for git: {s}"))
Expand Down
8 changes: 4 additions & 4 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ impl LockedPackage {
return false;
}

if let Source::Repository { ref repository } = self.source {
if !repo_urls.contains(repository.as_str()) {
return false;
}
if let Source::Repository { ref repository } = self.source
&& !repo_urls.contains(repository.as_str())
{
return false;
}

true
Expand Down
Loading