Skip to content
Open
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
15 changes: 12 additions & 3 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub enum FileType {
NamedPipe,
Mount,
RegularFile,
Unknown,
}

pub trait Handle {
Expand Down Expand Up @@ -134,6 +135,7 @@ pub trait Entry {
ffi::AE_IFMT => FileType::Mount,
ffi::AE_IFREG => FileType::RegularFile,
ffi::AE_IFSOCK => FileType::Socket,
0 => FileType::Unknown,
code => unreachable!("undefined filetype: {}", code),
}
}
Expand Down Expand Up @@ -161,10 +163,16 @@ pub trait Entry {
unsafe { ffi::archive_entry_size(self.entry()) }
}

fn symlink(&self) -> &str {
let c_str: &CStr = unsafe { CStr::from_ptr(ffi::archive_entry_symlink(self.entry())) };
fn symlink(&self) -> Option<&str> {
let c_str: &CStr = unsafe {
let ptr = ffi::archive_entry_symlink(self.entry());
if ptr.is_null() {
return None;
}
CStr::from_ptr(ptr)
};
let buf: &[u8] = c_str.to_bytes();
str::from_utf8(buf).unwrap()
Some(str::from_utf8(buf).unwrap())
}

fn set_filetype(&mut self, file_type: FileType) {
Expand All @@ -178,6 +186,7 @@ pub trait Entry {
FileType::Mount => ffi::AE_IFMT,
FileType::RegularFile => ffi::AE_IFREG,
FileType::Socket => ffi::AE_IFSOCK,
FileType::Unknown => 0,
};
ffi::archive_entry_set_filetype(self.entry(), file_type);
}
Expand Down