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

header: set entry_size() to 0 for hardlinks #314

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/header.rs
Expand Up @@ -298,6 +298,9 @@ impl Header {
///
/// May return an error if the field is corrupted.
pub fn entry_size(&self) -> io::Result<u64> {
if self.entry_type().is_hard_link() {
return Ok(0);
}
num_field_wrapper_from(&self.as_old().size).map_err(|err| {
io::Error::new(
err.kind(),
Expand Down
27 changes: 20 additions & 7 deletions tests/header/mod.rs
@@ -1,12 +1,14 @@
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::Path;
use std::{iter, mem, thread, time};

use std::{
fs::{self, File},
io::{self, Write},
iter, mem,
path::Path,
thread, time,
};

use tar::{EntryType, GnuHeader, Header, HeaderMode};
use tempfile::Builder;

use tar::{GnuHeader, Header, HeaderMode};

#[test]
fn default_gnu() {
let mut h = Header::new_gnu();
Expand Down Expand Up @@ -244,3 +246,14 @@ fn byte_slice_conversion() {
let b_conv: &[u8] = Header::from_byte_slice(h.as_bytes()).as_bytes();
assert_eq!(b, b_conv);
}

#[test]
fn hardlink_entry_size() {
let mut h = Header::new_ustar();
let p = Path::new("a").join(&vec!["a"; 100].join(""));
h.set_entry_type(EntryType::Link);
t!(h.set_path(&p));
t!(h.set_link_name("foo"));
h.set_size(200);
assert_eq!(t!(h.entry_size()), 0);
}