mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
optional script unpacking
This commit is contained in:
@@ -1123,8 +1123,10 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
|
||||
if tokio::fs::metadata(&script_dir).await.is_err() {
|
||||
tokio::fs::create_dir_all(&script_dir).await?;
|
||||
}
|
||||
let mut tar = tokio_tar::Archive::new(rdr.scripts().await?);
|
||||
tar.unpack(script_dir).await?;
|
||||
if let Some(hdl) = rdr.scripts().await? {
|
||||
let mut tar = tokio_tar::Archive::new(hdl);
|
||||
tar.unpack(script_dir).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -121,10 +121,10 @@ impl<
|
||||
std::io::copy(&mut self.scripts, &mut writer)
|
||||
.with_ctx(|_| (crate::ErrorKind::Filesystem, "Copying Scripts"))?;
|
||||
let new_pos = writer.inner_mut().stream_position()?;
|
||||
header.table_of_contents.scripts = FileSection {
|
||||
header.table_of_contents.scripts = Some(FileSection {
|
||||
position,
|
||||
length: new_pos - position,
|
||||
};
|
||||
});
|
||||
position = new_pos;
|
||||
|
||||
// header
|
||||
|
||||
@@ -75,7 +75,7 @@ pub struct TableOfContents {
|
||||
pub icon: FileSection,
|
||||
pub docker_images: FileSection,
|
||||
pub assets: FileSection,
|
||||
pub scripts: FileSection,
|
||||
pub scripts: Option<FileSection>,
|
||||
}
|
||||
impl TableOfContents {
|
||||
pub fn serialize<W: Write>(&self, mut writer: W) -> std::io::Result<()> {
|
||||
@@ -95,7 +95,10 @@ impl TableOfContents {
|
||||
self.docker_images
|
||||
.serialize_entry("docker_images", &mut writer)?;
|
||||
self.assets.serialize_entry("assets", &mut writer)?;
|
||||
self.scripts.serialize_entry("scripts", &mut writer)?;
|
||||
match self.scripts {
|
||||
None => FileSection::default().serialize_entry("scripts", &mut writer),
|
||||
Some(a) => a.serialize_entry("scripts", &mut writer),
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
pub async fn deserialize<R: AsyncRead + Unpin>(mut reader: R) -> std::io::Result<Self> {
|
||||
@@ -134,7 +137,7 @@ impl TableOfContents {
|
||||
icon: from_table(&table, "icon")?,
|
||||
docker_images: from_table(&table, "docker_images")?,
|
||||
assets: from_table(&table, "assets")?,
|
||||
scripts: from_table(&table, "scripts")?,
|
||||
scripts: table.get("scripts".as_bytes()).cloned(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,10 @@ impl<R: AsyncRead + AsyncSeek + Unpin> S9pkReader<R> {
|
||||
Ok(self.read_handle(self.toc.assets).await?)
|
||||
}
|
||||
|
||||
pub async fn scripts<'a>(&'a mut self) -> Result<ReadHandle<'a, R>, Error> {
|
||||
Ok(self.read_handle(self.toc.scripts).await?)
|
||||
pub async fn scripts<'a>(&'a mut self) -> Result<Option<ReadHandle<'a, R>>, Error> {
|
||||
Ok(match self.toc.scripts {
|
||||
None => None,
|
||||
Some(a) => Some(self.read_handle(a).await?),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user