feat: process libarchive entries using Read API
This commit is contained in:
parent
5743f4a3a5
commit
2e118d0283
7 changed files with 174 additions and 27 deletions
|
|
@ -1,3 +1,5 @@
|
|||
mod manager;
|
||||
|
||||
use axum::extract::{BodyStream, Path, State};
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
|
|
@ -6,6 +8,10 @@ use axum::Router;
|
|||
use futures::StreamExt;
|
||||
use futures::TryFutureExt;
|
||||
use futures::TryStreamExt;
|
||||
use libarchive::archive::Entry;
|
||||
use libarchive::read::Archive;
|
||||
use libarchive::read::Builder;
|
||||
use std::io::Read;
|
||||
use tokio::{fs, io, io::AsyncWriteExt};
|
||||
use tower_http::services::ServeDir;
|
||||
use uuid::Uuid;
|
||||
|
|
@ -46,5 +52,27 @@ async fn post_package_archive(
|
|||
.await?;
|
||||
}
|
||||
|
||||
let mut builder = Builder::new();
|
||||
builder
|
||||
.support_format(libarchive::archive::ReadFormat::Tar)
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
builder
|
||||
.support_filter(libarchive::archive::ReadFilter::All)
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
let mut ar = builder
|
||||
.open_file(&path)
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
for entry in ar.entries() {
|
||||
let mut entry = entry.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
||||
if entry.pathname() == ".PKGINFO" {
|
||||
let mut buffer = String::new();
|
||||
entry.read_to_string(&mut buffer);
|
||||
|
||||
println!("{}", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue