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

tidy 'header' implementation #254

Merged
merged 3 commits into from Jul 23, 2021
Merged
Changes from 1 commit
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
28 changes: 16 additions & 12 deletions src/header.rs
Expand Up @@ -26,6 +26,7 @@ pub struct Header {
/// Declares the information that should be included when filling a Header
/// from filesystem metadata.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum HeaderMode {
/// All supported metadata, including mod/access times and ownership will
/// be included.
Expand All @@ -34,9 +35,6 @@ pub enum HeaderMode {
/// Only metadata that is directly relevant to the identity of a file will
/// be included. In particular, ownership and mod/access times are excluded.
Deterministic,

#[doc(hidden)]
__Nonexhaustive,
}

/// Representation of the header of an entry in an archive
Expand Down Expand Up @@ -615,10 +613,14 @@ impl Header {
/// major device number.
pub fn set_device_major(&mut self, major: u32) -> io::Result<()> {
if let Some(ustar) = self.as_ustar_mut() {
return Ok(ustar.set_device_major(major));
return {
ustar.set_device_major(major);
Ok(())
};
danieleades marked this conversation as resolved.
Show resolved Hide resolved
}
if let Some(gnu) = self.as_gnu_mut() {
Ok(gnu.set_device_major(major))
gnu.set_device_major(major);
Ok(())
} else {
Err(other("not a ustar or gnu archive, cannot set dev_major"))
}
Expand Down Expand Up @@ -647,10 +649,14 @@ impl Header {
/// minor device number.
pub fn set_device_minor(&mut self, minor: u32) -> io::Result<()> {
if let Some(ustar) = self.as_ustar_mut() {
return Ok(ustar.set_device_minor(minor));
return {
ustar.set_device_minor(minor);
Ok(())
};
}
if let Some(gnu) = self.as_gnu_mut() {
Ok(gnu.set_device_minor(minor))
gnu.set_device_minor(minor);
Ok(())
} else {
Err(other("not a ustar or gnu archive, cannot set dev_minor"))
}
Expand Down Expand Up @@ -755,7 +761,6 @@ impl Header {
};
self.set_mode(fs_mode);
}
HeaderMode::__Nonexhaustive => panic!(),
}

// Note that if we are a GNU header we *could* set atime/ctime, except
Expand Down Expand Up @@ -815,7 +820,6 @@ impl Header {
let fs_mode = if meta.is_dir() { 0o755 } else { 0o644 };
self.set_mode(fs_mode);
}
HeaderMode::__Nonexhaustive => panic!(),
}

let ft = meta.file_type();
Expand Down Expand Up @@ -940,7 +944,7 @@ impl UstarHeader {
} else {
let mut bytes = Vec::new();
let prefix = truncate(&self.prefix);
if prefix.len() > 0 {
if !prefix.is_empty() {
bytes.extend_from_slice(prefix);
bytes.push(b'/');
}
Expand Down Expand Up @@ -1113,8 +1117,8 @@ impl GnuHeader {
fn fullname_lossy(&self) -> String {
format!(
"{}:{}",
String::from_utf8_lossy(&self.groupname_bytes()),
String::from_utf8_lossy(&self.username_bytes()),
String::from_utf8_lossy(self.groupname_bytes()),
String::from_utf8_lossy(self.username_bytes()),
)
}

Expand Down