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

removed support for zip archives #34

Merged
merged 3 commits into from
Aug 21, 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
137 changes: 1 addition & 136 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ rusqlite = { version = "0.32.1", features = ["bundled"] }
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
url = "2.5.0"
zip = { version = "2.2.0", default-features = false, features = ["deflate"] }
zstd = "0.13.0"

[dev-dependencies]
Expand Down
7 changes: 2 additions & 5 deletions src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

fn get_link_to_db_md5(url: &Url) -> Result<Url> {
let url_str = url.as_str();
if url_str.ends_with(".sql.zip") {
let new_url_str = url_str.replace(".sql.zip", ".sql.md5");
Ok(Url::parse(&new_url_str)?)
} else if url_str.ends_with(".sql.zst") {
if url_str.ends_with(".sql.zst") {

Check warning on line 17 in src/checksum.rs

View check run for this annotation

Codecov / codecov/patch

src/checksum.rs#L17

Added line #L17 was not covered by tests
let new_url_str = url_str.replace(".sql.zst", ".sql.md5");
Ok(Url::parse(&new_url_str)?)
} else {
anyhow::bail!("URL does not end with .sql.zip")
anyhow::bail!("URL does not end with .sql.zst")
}

Check warning on line 22 in src/checksum.rs

View check run for this annotation

Codecov / codecov/patch

src/checksum.rs#L21-L22

Added lines #L21 - L22 were not covered by tests
}

fn get_link_to_archive_md5(url: &Url) -> Result<Url> {
Expand Down
20 changes: 7 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod go_spacemesh;
mod parsers;
mod read_error_response;
mod reader_with_bytes;
mod reader_with_progress;
mod sql;
mod unpack;
mod user_agent;
Expand Down Expand Up @@ -178,21 +177,14 @@ fn main() -> anyhow::Result<()> {
max_retries,
} => {
let dir_path = node_data;
let temp_file_path = dir_path.join("state.download");
let redirect_file_path = dir_path.join("state.url");
let archive_zip_file_path = dir_path.join("state.zip");
let archive_zstd_file_path = dir_path.join("state.zst");
let archive_file_path = dir_path.join("state.zst");
let unpacked_file_path = dir_path.join("state_downloaded.sql");
let final_file_path = dir_path.join("state.sql");
let wal_file_path = dir_path.join("state.sql-wal");

// Download archive if needed
let archive_file_path = if archive_zip_file_path.try_exists().unwrap_or(false) {
archive_zip_file_path
} else if archive_zstd_file_path.try_exists().unwrap_or(false) {
archive_zstd_file_path
} else {
let archive_file_path = archive_zstd_file_path;
if !archive_file_path.try_exists().unwrap_or(false) {
println!("Downloading the latest database...");
let url = if redirect_file_path.try_exists().unwrap_or(false) {
std::fs::read_to_string(&redirect_file_path)?
Expand All @@ -206,6 +198,7 @@ fn main() -> anyhow::Result<()> {
download_url.to_string()
};

let temp_file_path = dir_path.join("state.download");
if let Some(dir) = temp_file_path.parent() {
std::fs::create_dir_all(dir)?;
}
Expand All @@ -214,7 +207,8 @@ fn main() -> anyhow::Result<()> {
.create(true)
.read(true)
.append(true)
.open(&temp_file_path)?;
.open(&temp_file_path)
.with_context(|| format!("creating temp file: {}", temp_file_path.display()))?;

if let Err(e) = download_with_retries(
&url,
Expand All @@ -232,8 +226,7 @@ fn main() -> anyhow::Result<()> {
// Rename `state.download` -> `state.zst`
std::fs::rename(&temp_file_path, &archive_file_path)?;
println!("Archive downloaded!");
archive_file_path
};
}

if redirect_file_path.try_exists().unwrap_or(false) {
println!("Verifying the checksum, it may take some time...");
Expand Down Expand Up @@ -262,6 +255,7 @@ fn main() -> anyhow::Result<()> {
}
Err(e) => {
if let Some(io_err) = e.downcast_ref::<std::io::Error>() {
// FIXME: use ErrorKind::StorageFull once it's stabilized (https://github.com/rust-lang/rust/issues/86442)
if io_err.raw_os_error() == Some(28) {
eprintln!("Cannot unpack archive: not enough disk space");
std::fs::remove_file(&unpacked_file_path)?;
Expand Down
34 changes: 0 additions & 34 deletions src/reader_with_progress.rs

This file was deleted.

Loading