Skip to content

Commit

Permalink
revert: do not update config file on update
Browse files Browse the repository at this point in the history
  • Loading branch information
beeb committed Aug 21, 2024
1 parent 632a725 commit 2612f3b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
10 changes: 2 additions & 8 deletions src/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs;

use super::Result;
use crate::{
config::{get_config_path, read_config_deps, read_soldeer_config, update_deps, Dependency},
config::{get_config_path, read_config_deps, read_soldeer_config, Dependency},
errors::LockError,
install::{ensure_dependencies_dir, Progress as InstallProgress},
lock::generate_lockfile_contents,
Expand Down Expand Up @@ -46,17 +46,11 @@ pub(crate) async fn update_command(cmd: Update) -> Result<()> {
let install_progress = InstallProgress::new(&multi, dependencies.len() as u64);
let progress = Progress::new(&install_progress, dependencies.len() as u64);
progress.start_all();
let new_items =
let new_locks =
update_dependencies(&dependencies, config.recursive_deps, progress.clone()).await?;
progress.stop_all();
multi.stop();

let (new_deps, new_locks): (Vec<_>, Vec<_>) = new_items.into_iter().unzip();

// update config file
update_deps(&new_deps, &config_path)?;
success("Updated config file")?;

let new_lockfile_content = generate_lockfile_contents(new_locks);
fs::write(LOCK_FILE.as_path(), new_lockfile_content).map_err(LockError::IOError)?;
success("Updated lockfile")?;
Expand Down
16 changes: 0 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,6 @@ pub fn add_to_config(dependency: &Dependency, config_path: impl AsRef<Path>) ->
Ok(())
}

pub fn update_deps(dependencies: &[Dependency], config_path: impl AsRef<Path>) -> Result<()> {
let contents = fs::read_to_string(&config_path)?;
let mut doc: DocumentMut = contents.parse::<DocumentMut>()?;
// in case we don't have the dependencies section defined in the config file, we add it
if !doc.contains_table("dependencies") {
doc.insert("dependencies", Item::Table(Table::default()));
}
let deps = doc["dependencies"].as_table_mut().expect("dependencies should be a table");
for dep in dependencies {
let (name, value) = dep.to_toml_value();
deps.insert(&name, value);
}
fs::write(config_path, doc.to_string())?;
Ok(())
}

pub fn delete_config(dependency_name: &str, path: impl AsRef<Path>) -> Result<Dependency> {
let contents = fs::read_to_string(&path)?;
let mut doc: DocumentMut = contents.parse::<DocumentMut>().expect("invalid doc");
Expand Down
10 changes: 5 additions & 5 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub async fn update_dependencies(
dependencies: &[Dependency],
recursive_deps: bool,
progress: Progress,
) -> Result<Vec<(Dependency, LockEntry)>> {
) -> Result<Vec<LockEntry>> {
let mut set = JoinSet::new();
for dep in dependencies {
set.spawn({
Expand All @@ -66,7 +66,7 @@ pub async fn update_dependency(
dependency: &Dependency,
recursive_deps: bool,
progress: Progress,
) -> Result<(Dependency, LockEntry)> {
) -> Result<LockEntry> {
// we can't update dependencies that are http with a custom URL or git dependencies with a
// commit hash
let new_dependency = match dependency {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub async fn update_dependency(
.build()
.into();
progress.install_progress.increment_all();
Ok((new_dependency, lock))
Ok(lock)
}
Dependency::Git(ref dep) if dep.rev.is_some() => {
// check integrity against the existing version since we can't update to a new rev
Expand All @@ -169,7 +169,7 @@ pub async fn update_dependency(
progress.install_progress,
)
.await?;
Ok((new_dependency, new_lock))
Ok(new_lock)
}
_ => {
// for http dependencies, we simply re-install them
Expand All @@ -180,7 +180,7 @@ pub async fn update_dependency(
progress.install_progress,
)
.await?;
Ok((new_dependency, lock))
Ok(lock)
}
}
}

0 comments on commit 2612f3b

Please sign in to comment.