Skip to content
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

Fix check command: request for zst and add user agent to all requests #7

Merged
merged 2 commits into from
Mar 5, 2024
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
3 changes: 3 additions & 0 deletions src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::io::{Read, Seek, SeekFrom, Write};
use std::path::Path;
use std::time::Instant;

use crate::user_agent::APP_USER_AGENT;

pub fn download_file(url: &str, file_path: &Path, redirect_path: &Path) -> Result<()> {
if let Some(dir) = file_path.parent() {
fs::create_dir_all(dir)?;
Expand All @@ -20,6 +22,7 @@ pub fn download_file(url: &str, file_path: &Path, redirect_path: &Path) -> Resul
let file_size = file.metadata()?.len();

let client = Client::builder()
.user_agent(APP_USER_AGENT)
.timeout(std::time::Duration::from_secs(30))
.build()?;
let mut response = client
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mod reader_with_progress;
mod sql;
mod unpack;
mod user_agent;
mod utils;

use checksum::*;
Expand Down Expand Up @@ -87,13 +88,13 @@
}
}

fn backup_or_fail(file_path: &PathBuf) -> () {

Check warning on line 91 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded unit return type

warning: unneeded unit return type --> src/main.rs:91:39 | 91 | fn backup_or_fail(file_path: &PathBuf) -> () { | ^^^^^^ help: remove the `-> ()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit = note: `#[warn(clippy::unused_unit)]` on by default
if file_path.exists() {
println!(
"Backing up file: {}",
file_path.file_name().unwrap().to_str().unwrap()
);
match backup_file(&file_path) {

Check warning on line 97 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/main.rs:97:23 | 97 | match backup_file(&file_path) { | ^^^^^^^^^^ help: change this to: `file_path` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
Ok(b) => {
let backup_name = b.to_str().expect("Cannot get a path of backed up file");
println!("File backed up to: {}", backup_name);
Expand Down Expand Up @@ -126,7 +127,7 @@
i64::from(get_last_layer_from_db(&db_file_path).or_else(|err| {
eprintln!("{}", err);
println!("Cannot read database, trating it as empty database");
return Ok::<i32, anyhow::Error>(0);

Check warning on line 130 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded `return` statement

warning: unneeded `return` statement --> src/main.rs:130:13 | 130 | return Ok::<i32, anyhow::Error>(0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return = note: `#[warn(clippy::needless_return)]` on by default help: remove `return` | 130 - return Ok::<i32, anyhow::Error>(0); 130 + Ok::<i32, anyhow::Error>(0) |
})?)
} else {
println!("Database file is not found");
Expand All @@ -141,7 +142,7 @@
let go_path_str = go_path
.to_str()
.expect("Cannot resolve path to go-spacemesh");
let go_version = get_version(&go_path_str)?;

Check warning on line 145 in src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/main.rs:145:38 | 145 | let go_version = get_version(&go_path_str)?; | ^^^^^^^^^^^^ help: change this to: `go_path_str` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
let quicksync_layer = fetch_latest_available_layer(&download_url, &go_version)?;
println!("Latest layer in cloud: {}", quicksync_layer);
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/user_agent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
5 changes: 4 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use std::{env, path::PathBuf};
use url::Url;

use crate::user_agent::APP_USER_AGENT;

pub fn strip_trailing_newline(input: &str) -> &str {
input.trim_end()
}
Expand Down Expand Up @@ -73,12 +75,13 @@

pub fn fetch_latest_available_layer(download_url: &Url, go_version: &str) -> Result<u64> {
let client = Client::builder()
.user_agent(APP_USER_AGENT)
.redirect(redirect::Policy::none())
.timeout(std::time::Duration::from_secs(30))
.build()?;

let path = format!("{}/state.zip", go_version);
let path = format!("{}/state.zst", go_version);
let url = build_url(&download_url, &path);

Check warning on line 84 in src/utils.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/utils.rs:84:23 | 84 | let url = build_url(&download_url, &path); | ^^^^^^^^^^^^^ help: change this to: `download_url` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default

let response = client.head(url).send()?;

Expand Down
Loading