Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sparse files #624

Merged
merged 1 commit into from
Oct 31, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add non-standard CompressionOptions support ([#584](https://github.com/wcampbell0x2a/backhand/pull/584))
- Add `CompressionAction::compression_options` to override the default compression options emitted during writing.
- Add `FilesystemWriter::set_emit_compression_options`
- Support sparse file extraction ([#624](https://github.com/wcampbell0x2a/backhand/pull/624))

### `backhand-cli`
- Add `--no-compression-options` to `add` and `replace` to remove compression options from image after modification.
Expand Down
15 changes: 14 additions & 1 deletion backhand-test/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,6 @@ fn test_socket_fifo() {
#[test]
#[cfg(any(feature = "zstd"))]
fn no_qemu_test_crates_zstd() {
tracing::trace!("nice");
const FILE_NAME: &str = "crates-io.squashfs";
let asset_defs = [TestAssetDef {
filename: FILE_NAME.to_string(),
Expand All @@ -519,3 +518,17 @@ fn no_qemu_test_crates_zstd() {

full_test(&asset_defs, FILE_NAME, TEST_PATH, 0, Verify::Extract, false);
}

#[test]
#[cfg(feature = "xz")]
fn test_slow_sparse_data_issue_623() {
const FILE_NAME: &str = "aosc-os_buildkit_20240916_amd64.squashfs";
let asset_defs = [TestAssetDef {
filename: FILE_NAME.to_string(),
hash: "02b0069d480df7c351b64e640025cb6b84890d8f9e377f15cc24fc70d5617905".to_string(),
url: "https://releases.aosc.io/os-amd64/buildkit/aosc-os_buildkit_20240916_amd64.squashfs"
.to_string(),
}];
const TEST_PATH: &str = "test-assets/test_sparse_data_issue_623";
full_test(&asset_defs, FILE_NAME, TEST_PATH, 0, Verify::Extract, true);
}
11 changes: 8 additions & 3 deletions backhand/src/filesystem/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ impl<'a, 'b> SquashfsRawData<'a, 'b> {
match block {
BlockFragment::Block(block) => {
let block_size = block.size() as usize;
// sparse file, don't read from reader, just fill with superblock.block size of 0's
if block_size == 0 {
*data = vec![0; self.file.system.block_size as usize];
return Ok(RawDataBlock { fragment: false, uncompressed: true });
}
data.resize(block_size, 0);
//NOTE: storing/restoring the file-pos is not required at the
//moment of writing, but in the future, it may.
Expand Down Expand Up @@ -346,10 +351,10 @@ impl<'a, 'b> SquashfsRawData<'a, 'b> {
input_buf: &mut Vec<u8>,
output_buf: &mut Vec<u8>,
) -> Result<(), BackhandError> {
//append to the output_buf is not allowed, it need to be empty
// append to the output_buf is not allowed, it need to be empty
assert!(output_buf.is_empty());
//input is already decompress, so just swap the input/output, so the
//output_buf contains the final data.
// input is already decompress, so just swap the input/output, so the
// output_buf contains the final data.
if data.uncompressed {
std::mem::swap(input_buf, output_buf);
} else {
Expand Down
Loading