Skip to content

Commit

Permalink
Merge pull request #612 from wcampbell0x2a/update-deku-0.18-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
wcampbell0x2a authored Sep 10, 2024
2 parents f04de50 + f6880cf commit 490e55d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion backhand-test/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn test_bin_unsquashfs(
assert_success: bool,
run_squashfs_tools_unsquashfs: bool,
) {
let tmp_dir = tempdir().unwrap();
let tmp_dir = tempdir_in(".").unwrap();
// Run "our" unsquashfs against the control
let cmd = get_base_command("unsquashfs-backhand")
.env("RUST_LOG", "trace")
Expand Down
2 changes: 1 addition & 1 deletion backhand/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
deku = "0.17.0"
deku = { version = "0.18.1", default-features = false, features = ["std"] }
tracing = { version = "0.1.40" }
thiserror = "1.0.63"
flate2 = { version = "1.0.33", optional = true, features = ["zlib-ng"] }
Expand Down
4 changes: 2 additions & 2 deletions backhand/src/compressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl CompressionAction for DefaultCompressor {
if let Some(options) = &fs_compressor.options {
trace!("writing compression options");
superblock.flags |= Flags::CompressorOptionsArePresent as u16;
let mut compression_opt_buf_out = vec![];
let mut compression_opt_buf_out = Cursor::new(vec![]);
let mut writer = Writer::new(&mut compression_opt_buf_out);
match options {
CompressionOptions::Gzip(gzip) => {
Expand All @@ -398,7 +398,7 @@ impl CompressionAction for DefaultCompressor {
superblock.block_size,
Kind { inner: kind.inner.clone() },
);
metadata.write_all(&compression_opt_buf_out)?;
metadata.write_all(compression_opt_buf_out.get_ref())?;
metadata.finalize(&mut w)?;
}

Expand Down
21 changes: 12 additions & 9 deletions backhand/src/filesystem/writer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ffi::OsStr;
use std::io::{Read, Seek, SeekFrom, Write};
use std::io::{Cursor, Read, Seek, SeekFrom, Write};
use std::num::NonZeroUsize;
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down Expand Up @@ -622,11 +622,11 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
trace!("WRITING DIR: {block_offset:#02x?}");
let mut total_size: usize = 3;
for dir in Entry::into_dir(entries) {
let mut bytes = vec![];
let mut bytes = Cursor::new(vec![]);
let mut writer = Writer::new(&mut bytes);
dir.to_writer(&mut writer, kind.inner.type_endian)?;
total_size += bytes.len();
dir_writer.write_all(&bytes)?;
total_size += bytes.get_ref().len();
dir_writer.write_all(bytes.get_ref())?;
}
let entry = Entry::path(
filename,
Expand Down Expand Up @@ -831,25 +831,28 @@ impl<'a, 'b, 'c> FilesystemWriter<'a, 'b, 'c> {
W: Write + Seek,
{
let mut ptrs: Vec<u64> = vec![];
let mut table_bytes = Vec::with_capacity(table.len() * element_size);
let mut table_bytes = Cursor::new(Vec::with_capacity(table.len() * element_size));
let mut iter = table.iter().peekable();
while let Some(t) = iter.next() {
// convert fragment ptr to bytes
let mut table_writer = Writer::new(&mut table_bytes);
t.to_writer(&mut table_writer, self.kind.inner.type_endian)?;

// once table_bytes + next is over the maximum size of a metadata block, write
if ((table_bytes.len() + element_size) > METADATA_MAXSIZE) || iter.peek().is_none() {
if ((table_bytes.get_ref().len() + element_size) > METADATA_MAXSIZE)
|| iter.peek().is_none()
{
ptrs.push(w.stream_position()?);

// write metadata len
let len = metadata::set_if_uncompressed(table_bytes.len() as u16);
let len = metadata::set_if_uncompressed(table_bytes.get_ref().len() as u16);
let mut writer = Writer::new(&mut w);
len.to_writer(&mut writer, self.kind.inner.data_endian)?;
// write metadata bytes
w.write_all(&table_bytes)?;
w.write_all(table_bytes.get_ref())?;

table_bytes.clear();
table_bytes.get_mut().clear();
table_bytes.rewind()?;
}
}

Expand Down
6 changes: 3 additions & 3 deletions backhand/src/inode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Index Node for file or directory
use core::fmt;
use std::io::Write;
use std::io::{Cursor, Write};

use deku::prelude::*;

Expand Down Expand Up @@ -35,7 +35,7 @@ impl Inode {
superblock: &SuperBlock,
kind: &Kind,
) -> Entry<'a> {
let mut inode_bytes = vec![];
let mut inode_bytes = Cursor::new(vec![]);
let mut writer = Writer::new(&mut inode_bytes);
self.to_writer(
&mut writer,
Expand All @@ -49,7 +49,7 @@ impl Inode {
.unwrap();
let start = m_writer.metadata_start;
let offset = m_writer.uncompressed_bytes.len() as u16;
m_writer.write_all(&inode_bytes).unwrap();
m_writer.write_all(inode_bytes.get_ref()).unwrap();

Entry {
start,
Expand Down
2 changes: 1 addition & 1 deletion backhand/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Write for MetadataWriter {
}
}

pub fn read_block<R: Read>(
pub fn read_block<R: Read + Seek>(
reader: &mut R,
superblock: &SuperBlock,
kind: &Kind,
Expand Down

0 comments on commit 490e55d

Please sign in to comment.