-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updatehub: Add support for RawDelta objects
Signed-off-by: Jonathas-Conceicao <jonathas.conceicao@ossystems.com.br>
- Loading branch information
Jonathas-Conceicao
committed
Aug 25, 2021
1 parent
c15bee1
commit b01f9ff
Showing
5 changed files
with
75 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ mod flash; | |
mod imxkobs; | ||
mod mender; | ||
mod raw; | ||
mod raw_delta; | ||
mod tarball; | ||
mod test; | ||
mod ubifs; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2021 O.S. Systems Sofware LTDA | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::{Context, Error, Result}; | ||
use crate::{ | ||
object::Installer, | ||
utils::{self, definitions::TargetTypeExt, delta}, | ||
}; | ||
|
||
use pkg_schema::{definitions, objects}; | ||
use slog_scope::info; | ||
|
||
#[async_trait::async_trait(?Send)] | ||
impl Installer for objects::RawDelta { | ||
async fn check_requirements(&self, context: &Context) -> Result<()> { | ||
info!("'raw-delta' handle checking requirements"); | ||
|
||
if let definitions::TargetType::Device(dev) = self.target.valid()? { | ||
let seed = get_seed_path(self, context); | ||
let required_size = delta::get_required_size(&seed, dev).await?; | ||
utils::fs::ensure_disk_space(&dev, required_size)?; | ||
return Ok(()); | ||
} | ||
Err(Error::InvalidTargetType(self.target.clone())) | ||
} | ||
|
||
async fn install(&self, context: &Context) -> Result<()> { | ||
info!("'raw-delta' handler Install {} ({})", self.filename, self.sha256sum); | ||
|
||
let target = self.target.get_target()?; | ||
// Clone's chunk size is used from archives definition, | ||
// so we can ignore this parameter here | ||
let _ = self.chunk_size.0; | ||
let source = get_seed_path(self, context); | ||
|
||
delta::clone(&source, &target, self.seek).await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
fn get_seed_path(obj: &objects::RawDelta, context: &Context) -> String { | ||
if context.offline_update { | ||
format!("{:?}", context.download_dir.join(&obj.sha256sum)) | ||
} else { | ||
format!("{}/{}", context.base_url, &obj.sha256sum) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::object::installer::tests::create_echo_bins; | ||
use pretty_assertions::assert_eq; | ||
use std::env; | ||
|
||
fn fake_raw_delta_obj() -> objects::RawDelta { | ||
objects::RawDelta { | ||
filename: "etc/passwd".to_string(), | ||
sha256sum: "cfe2be1c64b03875008".to_string(), | ||
target: definitions::TargetType::Device(std::path::PathBuf::from("/dev/sda1")), | ||
chunk_size: definitions::ChunkSize::default(), | ||
seek: 0, | ||
size: 1024, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters