Skip to content
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
9 changes: 9 additions & 0 deletions crates/griffr-cli/src/commands/install/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ pub(super) async fn install_hypergryph(
.context("Failed to build the install content plan")?;

let change_start = start_install_change(&install_path, &change_state)?;
content_plan
.reclaim_payload_temps(change_state.sync_vfs, false)
.await?;
match change_start {
InstallChangeStart::New => {}
InstallChangeStart::Resume => {
Expand Down Expand Up @@ -245,6 +248,9 @@ pub(super) async fn install_hypergryph(
sync_launcher_metadata(&api_client, &install_path, content_plan.snapshot())
.await
.context("Failed to sync launcher metadata after resumed install verification")?;
content_plan
.reclaim_payload_temps(change_state.sync_vfs, true)
.await?;
finish_install_change(&install_path, &change_state)
.context("Failed to remove the install change marker")?;
ui::print_success("Install resume finished");
Expand Down Expand Up @@ -474,6 +480,9 @@ pub(super) async fn install_hypergryph(
sync_launcher_metadata(&api_client, &install_path, content_plan.snapshot())
.await
.context("Failed to sync launcher metadata after final install verification")?;
content_plan
.reclaim_payload_temps(change_state.sync_vfs, true)
.await?;
finish_install_change(&install_path, &change_state)
.context("Failed to remove the install change marker")?;

Expand Down
13 changes: 13 additions & 0 deletions crates/griffr-cli/src/commands/update/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ pub(super) async fn update_internal(
let mut content_plan =
ContentPlan::from_snapshot(&local.install_path, manifest_snapshot, &vfs_plan.claims)
.context("Failed to build the update content plan")?;
content_plan
.reclaim_payload_temps(state.sync_vfs, false)
.await?;
let post_update = verify_updated_install(
api_client,
&install_target.api,
Expand All @@ -307,6 +310,9 @@ pub(super) async fn update_internal(
)
.await?;
debug_assert_eq!(post_update, PostUpdateResult::Verified);
content_plan
.reclaim_payload_temps(state.sync_vfs, true)
.await?;
finish_install_change(&local.install_path, state)
.context("Failed to remove the install change marker")?;
ui::print_success(format!("Unfinished {} target verified", state.kind));
Expand Down Expand Up @@ -607,6 +613,10 @@ pub(super) async fn update_internal(
)),
}

content_plan
.reclaim_payload_temps(change_state.sync_vfs, false)
.await?;

// Delete intent belongs to the compatible official patch even when its
// payload loses the delivery comparison. The patch apply route itself
// retains ownership of deletes and releases bases after their consumers.
Expand Down Expand Up @@ -744,6 +754,9 @@ pub(super) async fn update_internal(
)
.await?;
if post_update == PostUpdateResult::Verified {
content_plan
.reclaim_payload_temps(change_state.sync_vfs, true)
.await?;
finish_install_change(&local.install_path, &change_state)
.context("Failed to remove the install change marker")?;
ui::print_success("Update finished");
Expand Down
8 changes: 8 additions & 0 deletions crates/griffr-cli/src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ impl RepairTransaction {
sync_launcher_metadata(api_client, install_path, content_plan.snapshot())
.await
.context("Failed to sync launcher metadata after repair")?;
content_plan
.reclaim_payload_temps(self.scope != crate::VerifyScopeArg::Core, true)
.await?;
if let Some(state) = self.change.as_ref() {
finish_install_change(install_path, state)
.context("Failed to remove the install change marker")?;
Expand Down Expand Up @@ -559,6 +562,11 @@ async fn verify_one(
&vfs_plan,
text_output,
)?;
if execute_repairs && effective_scope != crate::VerifyScopeArg::Resources {
content_plan
.reclaim_payload_temps(effective_scope != crate::VerifyScopeArg::Core, false)
.await?;
}
let summary = run_integrity_pool(
&content_plan,
match (effective_scope, execute_repairs) {
Expand Down
27 changes: 21 additions & 6 deletions crates/griffr-cli/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct StepProgress {
label: String,
verbose: bool,
started: Arc<AtomicBool>,
terminal: Arc<AtomicBool>,
plain: bool,
last_plain: Arc<AtomicU64>,
multi: Option<Arc<MultiProgress>>,
Expand Down Expand Up @@ -64,6 +65,7 @@ impl StepProgress {
label: label.into(),
verbose,
started: Arc::new(AtomicBool::new(false)),
terminal: Arc::new(AtomicBool::new(false)),
plain: !std::io::stderr().is_terminal(),
last_plain: Arc::new(AtomicU64::new(u64::MAX)),
multi,
Expand Down Expand Up @@ -175,17 +177,30 @@ impl StepProgress {
}

pub fn finish(&self) {
if crate::ui::is_quiet() || !self.started.load(Ordering::Acquire) {
self.finish_with_status(None);
}

fn finish_with_status(&self, failure: Option<&str>) {
if crate::ui::is_quiet()
|| !self.started.load(Ordering::Acquire)
|| self.terminal.swap(true, Ordering::AcqRel)
{
return;
}
let done = self.bar.position();
let total = self.bar.length().unwrap_or(done);
let status = if failure.is_some() { "failed" } else { "done" };
let message = format!("{} {} ({}/{})", self.label, status, done, total);
if self.plain {
eprintln!("{}: done ({}/{})", self.label, done, total);
return;
eprintln!("{message}");
}
// Abandon preserves the observed position; finish_with_message forces
// the position to the target even when work failed.
if failure.is_some() {
self.bar.abandon_with_message(message);
} else {
self.bar.finish_with_message(message);
}
self.bar
.finish_with_message(format!("{} done ({}/{})", self.label, done, total));
}

fn ensure_started(&self, total: u64) {
Expand Down Expand Up @@ -322,7 +337,7 @@ fn apply_update(route: &ProgressRoute, update: ProgressUpdate) {
}
}
ProgressUpdate::Finished { .. } => route.bar.finish(),
ProgressUpdate::Failed { .. } => route.bar.finish(),
ProgressUpdate::Failed { reason, .. } => route.bar.finish_with_status(Some(&reason)),
ProgressUpdate::Started { .. } => {}
}
}
Expand Down
26 changes: 26 additions & 0 deletions crates/griffr-cli/src/progress/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,29 @@ fn rendered_prefix_never_rounds_an_incomplete_count_to_100() {
progress.update_count(13_315, 13_315, "");
assert_eq!(progress.bar.prefix(), "100%");
}

#[test]
fn failed_progress_is_terminal_and_keeps_observed_position() {
let progress = CountAndByteProgress::new("verify", "repair.download", false);
hide_group(&progress.bytes);
let lane = ProgressLane::INTEGRITY_DOWNLOAD;
let session = progress.start(ProgressLane::INTEGRITY_VERIFY, lane);
let sender = session.sender();
sender.emit(ProgressUpdate::Advanced {
lane,
finished: 32,
total: Some(128),
item: None,
});
sender.emit(ProgressUpdate::Failed {
lane,
item: None,
reason: "download failed after retries".to_owned(),
});
drop(sender);
session.finish();
progress.finish();
assert_eq!(progress.bytes.bar.position(), 32);
assert!(progress.bytes.bar.message().contains("failed"));
assert!(!progress.bytes.bar.message().contains("done"));
}
24 changes: 24 additions & 0 deletions crates/griffr-runtime/src/content_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,30 @@ impl ContentPlan {
.collect()
}

/// Retire obsolete ordinary payload temporaries at a quiescent install
/// transaction boundary. The manifest protects all still-planned targets.
pub async fn reclaim_payload_temps(
&self,
include_resources: bool,
completed: bool,
) -> Result<usize> {
let root = self.install_root.clone();
let targets = self
.files
.values()
.map(|file| file.physical_path.clone())
.collect::<Vec<_>>();
crate::compat_fs::run_blocking("reclaim payload temporaries", move || {
crate::install_change::temps::reclaim_payload_temps(
&root,
&targets,
include_resources,
completed,
)
})
.await
}

pub fn planned_files(&self) -> impl Iterator<Item = &PlannedContent> {
self.files.values()
}
Expand Down
25 changes: 17 additions & 8 deletions crates/griffr-runtime/src/download/extractor/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::time::Duration;
use compio::time::timeout;

use crate::error::{Error, Result};
use crate::preallocate_file;
use griffr_hypergryph_api::protocol::{RANGE_HEADER, USER_AGENT_HEADER};

const ARCHIVE_RANGE_SEND_TIMEOUT: Duration = Duration::from_secs(60);
Expand Down Expand Up @@ -129,7 +128,12 @@ pub(crate) async fn fetch_archive_range_to_cache(
path: part_path.clone(),
source,
})?;
preallocate_file(&file, &part_path, expected)?;
// Do not retain unwritten KEEP_SIZE allocation on Linux after interruption.
#[cfg(windows)]
if let Err(error) = crate::preallocate_file(&file, &part_path, expected) {
return crate::task_pool::download_write::close_http_output(file, &part_path, Err(error))
.await;
}

let flush_threshold = progress_buffer_bytes.max(64 * 1024) as u64;
let mut last_reported = resume_offset;
Expand All @@ -150,6 +154,17 @@ pub(crate) async fn fetch_archive_range_to_cache(
)
.await?;

crate::task_pool::download_write::close_http_output(file, &part_path, Ok(())).await?;

if current_offset > expected {
compio::fs::remove_file(&part_path)
.await
.map_err(|source| Error::IoAt {
action: "remove file or directory",
path: part_path.clone(),
source,
})?;
}
if current_offset != expected {
return Err(Error::Message {
context: "Download error: ",
Expand All @@ -160,12 +175,6 @@ pub(crate) async fn fetch_archive_range_to_cache(
});
}

file.close().await.map_err(|source| Error::IoAt {
action: "write to file",
path: part_path.clone(),
source,
})?;

save_archive_range_file(&part_path, &request.cache_path).await?;
Ok(expected)
}
Expand Down
5 changes: 3 additions & 2 deletions crates/griffr-runtime/src/http_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ pub async fn download_file(
|_| {},
)
.await?;
output.sync_data().await.map_err(|source| Error::IoAt {
let synced = output.sync_data().await.map_err(|source| Error::IoAt {
action: "write to file",
path: output_path.to_path_buf(),
source,
})?;
});
crate::task_pool::download_write::close_http_output(output, output_path, synced).await?;
Ok(griffr_core::to_hex(&hasher.finalize()))
}

Expand Down
2 changes: 2 additions & 0 deletions crates/griffr-runtime/src/install_change/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub(crate) mod temps;

use std::io::ErrorKind;
use std::path::{Path, PathBuf};

Expand Down
Loading
Loading