Skip to content

Commit 432e324

Browse files
committed
feat: implement update logic with zsync integration
- check_for_update: fetches zsync control file - perform_update: full delta update using zsync-rs - Submits source AppImage for block matching - Runs self-referential scan - Downloads missing blocks - Completes assembly with checksum verification
1 parent 765bed1 commit 432e324

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

src/updater.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::path::{Path, PathBuf};
22

3+
use zsync_rs::ZsyncAssembly;
4+
35
use crate::appimage::AppImage;
46
use crate::error::{Error, Result};
57
use crate::update_info::UpdateInfo;
68

79
pub struct Updater {
8-
#[allow(dead_code)]
910
appimage: AppImage,
10-
#[allow(dead_code)]
1111
update_info: UpdateInfo,
1212
output_dir: PathBuf,
1313
overwrite: bool,
@@ -61,10 +61,63 @@ impl Updater {
6161
}
6262

6363
pub fn check_for_update(&self) -> Result<bool> {
64-
todo!("Implement update check")
64+
let zsync_url = self.update_info.zsync_url()?;
65+
let http = zsync_rs::HttpClient::new();
66+
let _control = http
67+
.fetch_control_file(&zsync_url)
68+
.map_err(|e| Error::Zsync(format!("Failed to fetch control file: {}", e)))?;
69+
70+
let output_path = self.output_path();
71+
if output_path.exists() && !self.overwrite {
72+
return Err(Error::AppImage(format!(
73+
"Output file already exists: {}",
74+
output_path.display()
75+
)));
76+
}
77+
78+
Ok(true)
6579
}
6680

6781
pub fn perform_update(&self) -> Result<PathBuf> {
68-
todo!("Implement update")
82+
let zsync_url = self.update_info.zsync_url()?;
83+
let output_path = self.output_path();
84+
85+
if output_path.exists() && !self.overwrite {
86+
return Err(Error::AppImage(format!(
87+
"Output file already exists: {}",
88+
output_path.display()
89+
)));
90+
}
91+
92+
let assembly = ZsyncAssembly::from_url(&zsync_url, &output_path)
93+
.map_err(|e| Error::AppImage(format!("Failed to initialize zsync: {}", e)))?;
94+
95+
let mut assembly = assembly;
96+
97+
assembly
98+
.submit_source_file(self.appimage.path())
99+
.map_err(|e| Error::AppImage(format!("Failed to submit source file: {}", e)))?;
100+
101+
assembly
102+
.submit_self_referential()
103+
.map_err(|e| Error::AppImage(format!("Self-referential scan failed: {}", e)))?;
104+
105+
assembly
106+
.download_missing_blocks()
107+
.map_err(|e| Error::AppImage(format!("Failed to download blocks: {}", e)))?;
108+
109+
assembly
110+
.complete()
111+
.map_err(|e| Error::AppImage(format!("Failed to complete assembly: {}", e)))?;
112+
113+
Ok(output_path)
114+
}
115+
116+
pub fn progress(&self) -> Option<(u64, u64)> {
117+
None
118+
}
119+
120+
fn output_path(&self) -> PathBuf {
121+
self.appimage.path().to_path_buf()
69122
}
70123
}

0 commit comments

Comments
 (0)