Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Ensure temp download file is rewinded before reading it (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpalomaki authored Jul 26, 2021
1 parent 5005f11 commit 7dd7422
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terve"
version = "0.5.0"
version = "0.5.1"
edition = "2018"

[dependencies]
Expand Down
7 changes: 6 additions & 1 deletion src/terragrunt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{error::Error, fs::File, io::copy};
use std::{
error::Error,
fs::File,
io::{copy, Seek, SeekFrom},
};

use crate::{
http::HttpClient,
Expand Down Expand Up @@ -37,6 +41,7 @@ pub fn install_binary_version(
return Err(other.into());
}
}
tmp_file.seek(SeekFrom::Start(0))?;
let mut opt_file = File::create(&opt_file_path)?;
copy(&mut tmp_file, &mut opt_file)?;
#[cfg(unix)]
Expand Down
1 change: 0 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn check_sha256_sum(mut file: &File, expected_sha256: &str) -> Result<(), Bo
)
.into());
}
file.seek(SeekFrom::Start(0))?;
Ok(())
}

Expand Down
39 changes: 39 additions & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn test_workflows() {
};
test_terraform_all(&home_dir);
test_terragrunt_all(&home_dir);
test_install_old_terragrunt_with_no_shasums(&home_dir);
}

fn test_terraform_all(home_dir: &PathBuf) {
Expand Down Expand Up @@ -218,6 +219,44 @@ fn test_terragrunt_all(home_dir: &PathBuf) {
.stdout(predicate::str::is_empty());
}

// See https://github.com/superblk/terve/issues/21
fn test_install_old_terragrunt_with_no_shasums(home_dir: &PathBuf) {
terve()
.arg("i")
.arg("tg")
.arg("0.18.0")
.assert()
.success()
.code(0)
.stderr(predicate::str::contains(
"WARNING: Skipping SHA256 file integrity check",
))
.stdout(predicate::str::contains("Installed terragrunt 0.18.0"));

let opt_file_path = if cfg!(unix) {
home_dir
.join(".terve")
.join("opt")
.join("terragrunt")
.join("0.18.0")
} else {
home_dir
.join(".terve")
.join("opt")
.join("terragrunt.exe")
.join("0.18.0")
};

assert!(opt_file_path.metadata().unwrap().len() > 0);

Command::new(opt_file_path)
.arg("--version")
.assert()
.success()
.code(0)
.stdout(predicate::str::contains("0.18.0"));
}

fn terve() -> Command {
Command::cargo_bin("terve").unwrap()
}
Expand Down

0 comments on commit 7dd7422

Please sign in to comment.