mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-27 02:04:39 +10:00
write prefix for hardlinks on Disk restore
This commit is contained in:
@@ -139,6 +139,18 @@ pub trait Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn hardlink(&self) -> Option<&str> {
|
||||||
|
let c_str: &CStr = unsafe {
|
||||||
|
let ptr = ffi::archive_entry_hardlink(self.entry());
|
||||||
|
if ptr.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
CStr::from_ptr(ptr)
|
||||||
|
};
|
||||||
|
let buf: &[u8] = c_str.to_bytes();
|
||||||
|
Some(str::from_utf8(buf).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
fn pathname(&self) -> &str {
|
fn pathname(&self) -> &str {
|
||||||
let c_str: &CStr = unsafe { CStr::from_ptr(ffi::archive_entry_pathname(self.entry())) };
|
let c_str: &CStr = unsafe { CStr::from_ptr(ffi::archive_entry_pathname(self.entry())) };
|
||||||
let buf: &[u8] = c_str.to_bytes();
|
let buf: &[u8] = c_str.to_bytes();
|
||||||
@@ -149,6 +161,12 @@ pub trait Entry {
|
|||||||
unsafe { ffi::archive_entry_size(self.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())) };
|
||||||
|
let buf: &[u8] = c_str.to_bytes();
|
||||||
|
str::from_utf8(buf).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn set_filetype(&mut self, file_type: FileType) {
|
fn set_filetype(&mut self, file_type: FileType) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let file_type = match file_type {
|
let file_type = match file_type {
|
||||||
@@ -165,7 +183,14 @@ pub trait Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pathname(&mut self, path: PathBuf) {
|
fn set_link(&mut self, path: &PathBuf) {
|
||||||
|
unsafe {
|
||||||
|
let c_str = CString::new(path.to_str().unwrap()).unwrap();
|
||||||
|
ffi::archive_entry_set_link(self.entry(), c_str.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_pathname(&mut self, path: &PathBuf) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let c_str = CString::new(path.to_str().unwrap()).unwrap();
|
let c_str = CString::new(path.to_str().unwrap()).unwrap();
|
||||||
ffi::archive_entry_set_pathname(self.entry(), c_str.as_ptr());
|
ffi::archive_entry_set_pathname(self.entry(), c_str.as_ptr());
|
||||||
|
|||||||
@@ -113,7 +113,11 @@ impl Disk {
|
|||||||
if let Some(entry) = reader.next_header() {
|
if let Some(entry) = reader.next_header() {
|
||||||
if let Some(pfx) = prefix {
|
if let Some(pfx) = prefix {
|
||||||
let path = Path::new(pfx).join(entry.pathname());
|
let path = Path::new(pfx).join(entry.pathname());
|
||||||
entry.set_pathname(path);
|
entry.set_pathname(&path);
|
||||||
|
if entry.hardlink().is_some() {
|
||||||
|
let path = Path::new(pfx).join(entry.hardlink().unwrap());
|
||||||
|
entry.set_link(&path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
match self.write_header(entry) {
|
match self.write_header(entry) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
|
|||||||
Reference in New Issue
Block a user