🚑️ more efficient tar reading
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
74b8c7571d
commit
788de4da7d
2 changed files with 52 additions and 46 deletions
|
@ -51,7 +51,9 @@ async fn launch() -> _ {
|
|||
..Default::default()
|
||||
})
|
||||
.mount_assets()
|
||||
.mount("/", routes![
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
routes::index_page,
|
||||
routes::pkg_route,
|
||||
routes::push::upload_pkg,
|
||||
|
@ -64,7 +66,8 @@ async fn launch() -> _ {
|
|||
routes::user::end_session,
|
||||
routes::user::change_password,
|
||||
routes::user::change_password_post
|
||||
])
|
||||
],
|
||||
)
|
||||
.manage(config)
|
||||
.manage(shell)
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io::{Cursor, Read},
|
||||
io::{BufReader, Cursor, Read},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use based::get_pg;
|
||||
use sqlx::FromRow;
|
||||
use tar::Archive;
|
||||
use zstd::Decoder;
|
||||
|
||||
use super::{Repository, arch::Architecture};
|
||||
|
||||
|
@ -476,46 +477,48 @@ pub fn repo_add(db_file: &str, pkg_file: &str) {
|
|||
run_command(vec!["repo-add", db_file, pkg_file]);
|
||||
}
|
||||
|
||||
pub fn read_file_tar(tar: &PathBuf, file_path: &str) -> Option<String> {
|
||||
let mut file = File::open(tar).ok()?;
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
read_file_tar_raw(&buf, file_path)
|
||||
}
|
||||
pub fn read_file_tar(tar: &Path, file_path: &str) -> Option<String> {
|
||||
let file = File::open(tar).ok()?;
|
||||
let decoder = Decoder::new(BufReader::new(file)).ok()?;
|
||||
let mut archive = Archive::new(decoder);
|
||||
|
||||
pub fn read_file_tar_raw(tar: &[u8], file_path: &str) -> Option<String> {
|
||||
let uncompressed = zstd::decode_all(Cursor::new(tar)).unwrap();
|
||||
let content = Cursor::new(uncompressed);
|
||||
let mut a = Archive::new(content);
|
||||
|
||||
for e in a.entries().ok()? {
|
||||
let mut e = e.ok()?;
|
||||
let path = e.path().unwrap();
|
||||
let path = path.to_str().unwrap();
|
||||
if path == file_path {
|
||||
let mut file_content = Vec::new();
|
||||
e.read_to_end(&mut file_content).unwrap();
|
||||
return String::from_utf8(file_content).ok();
|
||||
for entry in archive.entries().ok()? {
|
||||
let mut entry = entry.ok()?;
|
||||
if entry.path().ok()?.to_str()? == file_path {
|
||||
let mut file_content = String::new();
|
||||
entry.read_to_string(&mut file_content).ok()?;
|
||||
return Some(file_content);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn list_tar_file(tar: &PathBuf) -> Option<Vec<String>> {
|
||||
let mut file = File::open(tar).ok()?;
|
||||
let mut buf = Vec::new();
|
||||
file.read_to_end(&mut buf).unwrap();
|
||||
let uncompressed = zstd::decode_all(Cursor::new(buf)).unwrap();
|
||||
let content = Cursor::new(uncompressed);
|
||||
let mut a = Archive::new(content);
|
||||
pub fn read_file_tar_raw(tar_data: &[u8], file_path: &str) -> Option<String> {
|
||||
let decoder = Decoder::new(Cursor::new(tar_data)).ok()?;
|
||||
let mut archive = Archive::new(decoder);
|
||||
|
||||
for entry in archive.entries().ok()? {
|
||||
let mut entry = entry.ok()?;
|
||||
if entry.path().ok()?.to_str()? == file_path {
|
||||
let mut file_content = String::new();
|
||||
entry.read_to_string(&mut file_content).ok()?;
|
||||
return Some(file_content);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn list_tar_file(tar: &Path) -> Option<Vec<String>> {
|
||||
let file = File::open(tar).ok()?;
|
||||
let decoder = Decoder::new(BufReader::new(file)).ok()?;
|
||||
let mut archive = Archive::new(decoder);
|
||||
let mut paths = Vec::new();
|
||||
|
||||
for e in a.entries().ok()? {
|
||||
let e = e.ok()?;
|
||||
let path = e.path().ok()?;
|
||||
let path = path.to_str()?;
|
||||
paths.push(path.to_string());
|
||||
for entry in archive.entries().ok()? {
|
||||
let entry = entry.ok()?;
|
||||
paths.push(entry.path().ok()?.to_string_lossy().into_owned());
|
||||
}
|
||||
|
||||
Some(paths)
|
||||
|
|
Loading…
Add table
Reference in a new issue