diff --git a/src/header.rs b/src/header.rs index 7e507fc7..c679ad5a 100644 --- a/src/header.rs +++ b/src/header.rs @@ -298,6 +298,9 @@ impl Header { /// /// May return an error if the field is corrupted. pub fn entry_size(&self) -> io::Result { + 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(), diff --git a/tests/header/mod.rs b/tests/header/mod.rs index 86692e33..0acd48cd 100644 --- a/tests/header/mod.rs +++ b/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(); @@ -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); +}