fix(server): actually serve desc & files in db archives
parent
fd1c2d3647
commit
b8d53f43b6
|
@ -314,6 +314,12 @@ pub trait Entry {
|
||||||
ffi::archive_entry_set_mode(self.entry_mut(), mode);
|
ffi::archive_entry_set_mode(self.entry_mut(), mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_size(&mut self, size: i64) {
|
||||||
|
unsafe {
|
||||||
|
ffi::archive_entry_set_size(self.entry_mut(), size);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -39,22 +39,32 @@ impl FileWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buf = [0; 8192];
|
let mut buf = [0; 4096];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match r.read(&mut buf) {
|
match r.read(&mut buf) {
|
||||||
Ok(0) => return Ok(()),
|
Ok(0) => return Ok(()),
|
||||||
Ok(written) => unsafe {
|
// Write entire buffer
|
||||||
match ffi::archive_write_data(
|
Ok(buf_len) => {
|
||||||
|
let mut written: usize = 0;
|
||||||
|
|
||||||
|
while written < buf_len {
|
||||||
|
let res = unsafe {
|
||||||
|
ffi::archive_write_data(
|
||||||
self.handle_mut(),
|
self.handle_mut(),
|
||||||
buf.as_ptr() as *const _,
|
&buf[written] as *const u8 as *const _,
|
||||||
written,
|
buf_len - written,
|
||||||
) as i32
|
)
|
||||||
{
|
} as isize;
|
||||||
ffi::ARCHIVE_OK => (),
|
|
||||||
_ => return Err(ArchiveError::from(self as &dyn Handle).into()),
|
// Negative values signal errors
|
||||||
};
|
if res < 0 {
|
||||||
},
|
return Err(ArchiveError::from(self as &dyn Handle).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
written += usize::try_from(res).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(err) => match err.kind() {
|
Err(err) => match err.kind() {
|
||||||
io::ErrorKind::Interrupted => (),
|
io::ErrorKind::Interrupted => (),
|
||||||
_ => return Err(err.into()),
|
_ => return Err(err.into()),
|
||||||
|
|
|
@ -65,9 +65,13 @@ impl RepoGroupManager {
|
||||||
// The desc file needs to be added to both archives
|
// The desc file needs to be added to both archives
|
||||||
let path_in_tar = PathBuf::from(entry.file_name()).join("desc");
|
let path_in_tar = PathBuf::from(entry.file_name()).join("desc");
|
||||||
let src_path = entry.path().join("desc");
|
let src_path = entry.path().join("desc");
|
||||||
|
let metadata = src_path.metadata()?;
|
||||||
|
|
||||||
let mut ar_entry = WriteEntry::new();
|
let mut ar_entry = WriteEntry::new();
|
||||||
ar_entry.set_pathname(&path_in_tar);
|
ar_entry.set_pathname(&path_in_tar);
|
||||||
|
// These small text files will definitely fit inside an i64
|
||||||
|
ar_entry.set_size(metadata.len().try_into().unwrap());
|
||||||
|
ar_entry.set_filetype(libarchive::archive::FileType::RegularFile);
|
||||||
ar_entry.set_mode(0o100644);
|
ar_entry.set_mode(0o100644);
|
||||||
|
|
||||||
ar_db.append_path(&mut ar_entry, &src_path)?;
|
ar_db.append_path(&mut ar_entry, &src_path)?;
|
||||||
|
@ -76,10 +80,14 @@ impl RepoGroupManager {
|
||||||
// The files file is only required in the files database
|
// The files file is only required in the files database
|
||||||
let path_in_tar = PathBuf::from(entry.file_name()).join("files");
|
let path_in_tar = PathBuf::from(entry.file_name()).join("files");
|
||||||
let src_path = entry.path().join("files");
|
let src_path = entry.path().join("files");
|
||||||
|
let metadata = src_path.metadata()?;
|
||||||
|
|
||||||
let mut ar_entry = WriteEntry::new();
|
let mut ar_entry = WriteEntry::new();
|
||||||
|
ar_entry.set_filetype(libarchive::archive::FileType::RegularFile);
|
||||||
ar_entry.set_pathname(&path_in_tar);
|
ar_entry.set_pathname(&path_in_tar);
|
||||||
ar_entry.set_mode(0o100644);
|
ar_entry.set_mode(0o100644);
|
||||||
|
// These small text files will definitely fit inside an i64
|
||||||
|
ar_entry.set_size(metadata.len().try_into().unwrap());
|
||||||
|
|
||||||
ar_files.append_path(&mut ar_entry, src_path)?;
|
ar_files.append_path(&mut ar_entry, src_path)?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue