-
Notifications
You must be signed in to change notification settings - Fork 3
v0.3.22 Release #72
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
v0.3.22 Release #72
Changes from all commits
0c60b72
c73b887
c7eeb67
af84edd
cc23f54
6c06b3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ use config::Towerfile; | |||||
| use tokio_tar::{Archive, Builder}; | ||||||
| use glob::glob; | ||||||
| use tmpdir::TmpDir; | ||||||
| use sha2::{Sha256, Digest}; | ||||||
|
|
||||||
| use async_compression::tokio::write::GzipEncoder; | ||||||
| use async_compression::tokio::bufread::GzipDecoder; | ||||||
|
|
@@ -54,6 +55,10 @@ pub struct Manifest { | |||||
| // modules_dir_name is the name of the modules directory within the package. | ||||||
| #[serde(default)] | ||||||
| pub modules_dir_name: String, | ||||||
|
|
||||||
| // checksum contains a hash of all the content in the package. | ||||||
| #[serde(default)] | ||||||
| pub checksum: String, | ||||||
| } | ||||||
|
|
||||||
| impl Manifest { | ||||||
|
|
@@ -165,6 +170,7 @@ impl Package { | |||||
| import_paths: vec![], | ||||||
| app_dir_name: "app".to_string(), | ||||||
| modules_dir_name: "modules".to_string(), | ||||||
| checksum: "".to_string(), | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -202,6 +208,11 @@ impl Package { | |||||
| let gzip = GzipEncoder::new(file); | ||||||
| let mut builder = Builder::new(gzip); | ||||||
|
|
||||||
| // These help us compute the integrity of the package contents overall. For each path, we'll | ||||||
| // store a hash of the contents written to the file. Then we'll hash the final content to | ||||||
| // create a fingerprint of the data. | ||||||
| let mut path_hashes = HashMap::new(); | ||||||
|
|
||||||
| // If the user didn't specify anything here we'll package everything under this directory | ||||||
| // and ship it to Tower. | ||||||
| let mut file_globs = spec.file_globs.clone(); | ||||||
|
|
@@ -228,6 +239,10 @@ impl Package { | |||||
| for (physical_path, logical_path) in file_paths { | ||||||
| // All of the app code goes into the "app" directory. | ||||||
| let logical_path = app_dir.join(logical_path); | ||||||
|
|
||||||
| let hash = compute_sha256_file(&physical_path).await?; | ||||||
| path_hashes.insert(logical_path.clone(), hash); | ||||||
|
|
||||||
| builder.append_path_with_name(physical_path, logical_path).await?; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -253,6 +268,10 @@ impl Package { | |||||
| // Now we write all of these paths to the modules directory. | ||||||
| for (physical_path, logical_path) in file_paths { | ||||||
| let logical_path = module_dir.join(logical_path); | ||||||
|
|
||||||
| let hash = compute_sha256_file(&physical_path).await?; | ||||||
| path_hashes.insert(logical_path.clone(), hash); | ||||||
|
|
||||||
| debug!("adding file {}", logical_path.display()); | ||||||
| builder.append_path_with_name(physical_path, logical_path).await?; | ||||||
| } | ||||||
|
|
@@ -266,6 +285,7 @@ impl Package { | |||||
| schedule: spec.schedule, | ||||||
| app_dir_name: app_dir.to_string_lossy().to_string(), | ||||||
| modules_dir_name: module_dir.to_string_lossy().to_string(), | ||||||
| checksum: compute_sha256_package(&path_hashes)?, | ||||||
| }; | ||||||
|
|
||||||
| // the whole manifest needs to be written to a file as a convenient way to avoid having to | ||||||
|
|
@@ -282,11 +302,10 @@ impl Package { | |||||
| "Towerfile", | ||||||
| ).await?; | ||||||
|
|
||||||
| // We'll need to delete the lines above here. | ||||||
| let mut gzip = builder.into_inner().await?; | ||||||
| gzip.shutdown().await?; | ||||||
|
|
||||||
| //// probably not explicitly required; however, makes the test suite pass so... | ||||||
| // probably not explicitly required; however, makes the test suite pass so... | ||||||
| let mut file = gzip.into_inner(); | ||||||
| file.shutdown().await?; | ||||||
|
|
||||||
|
|
@@ -490,3 +509,50 @@ fn should_ignore_file(p: &PathBuf) -> bool { | |||||
|
|
||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| fn compute_sha256_package(path_hashes: &HashMap<PathBuf, String>) -> Result<String, Error> { | ||||||
| let mut sorted_keys: Vec<&PathBuf> = path_hashes.keys().collect(); | ||||||
| sorted_keys.sort(); | ||||||
|
|
||||||
| // hasher that we'll use for computing the overall SHA256 hash. | ||||||
| let mut hasher = Sha256::new(); | ||||||
|
|
||||||
| for key in sorted_keys { | ||||||
| // We need to sort the keys so that we can compute a consistent hash. | ||||||
| let value = path_hashes.get(key).unwrap(); | ||||||
|
||||||
| let value = path_hashes.get(key).unwrap(); | |
| let value = path_hashes.get(key).expect("Key not found in path_hashes during SHA256 computation"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring for now, this needs a bit of work overall.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| [toolchain] | ||
| channel = "1.81" | ||
| channel = "1.88" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is very generic and doesn't provide specific information about the checksum computation failure. Consider including the actual error details to help users diagnose the issue.