Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion pkgsite-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub mod models;
use error::{PResult, PackagesSiteError};
pub use models::*;
use models::{
depends::Depends, index::Index, info::Info, rdepends::RDepends, search::Search,
depends::Depends, files::Files, index::Index, info::Info, rdepends::RDepends, search::Search,
updates::Updates,
};

Expand Down Expand Up @@ -180,6 +180,27 @@ impl PackagesSiteClient {
.json::<Updates>()
.await?)
}

pub async fn files(
&self,
arch: &str,
branch: &str,
package: &str,
version: &str,
) -> PResult<Files> {
Ok(self
.get_data(format!(
"{}/files/{}/{}/{}/{}?type=json",
&self.url,
arch.to_string(),
branch,
package,
version
))
.await?
.json::<Files>()
.await?)
}
}

#[cfg(test)]
Expand Down
35 changes: 35 additions & 0 deletions pkgsite-lib/src/models/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct File {
pub filename: Option<String>,
pub size: i64,
pub ftype: i16,
pub perm: i32,
pub uid: i64,
pub gid: i64,
pub uname: String,
pub gname: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Package {
pub package: String,
pub version: String,
pub architecture: String,
pub repo: String,
pub maintainer: String,
pub installed_size: i64,
pub filename: String,
pub size: i64,
pub sha256: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Files {
pub files: Vec<File>,
pub sodepends: Vec<String>,
pub soprovides: Vec<String>,
pub pkg_debtime: i32,
pub pkg: Package,
}
1 change: 1 addition & 0 deletions pkgsite-lib/src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod depends;
pub mod files;
pub mod index;
pub mod info;
pub mod rdepends;
Expand Down
23 changes: 23 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub enum Subcommands {
},
/// List 100 latest source updates
Updates,
/// List files for a package
Files {
arch: String,
repo: String,
package: String,
version: String,
},
}

#[cfg(feature = "argh")]
Expand All @@ -50,6 +57,7 @@ pub enum Subcommands {
Show(Show),
Search(Search),
Updates(Updates),
Files(Files),
}

#[cfg(feature = "argh")]
Expand Down Expand Up @@ -96,3 +104,18 @@ pub struct Search {
/// List 100 latest source updates
#[argh(subcommand, name = "updates")]
pub struct Updates {}

#[cfg(feature = "argh")]
#[derive(FromArgs, Debug)]
/// List files for a package
#[argh(subcommand, name = "files")]
pub struct Files {
#[argh(positional)]
pub arch: String,
#[argh(positional)]
pub repo: String,
#[argh(positional)]
pub package: String,
#[argh(positional)]
pub version: String,
}
16 changes: 16 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ async fn run() -> Result<()> {
Subcommands::Updates => {
print_res!(single pkgsite, updates, views::updates::UpdatesView);
}
Subcommands::Files {
arch,
repo,
package,
version,
} => {
print_res!(single pkgsite, files, views::files::FilesView, &arch, &repo, &package, &version);
}
},
None => {
print_res!(single pkgsite, index, views::index::IndexView);
Expand Down Expand Up @@ -72,6 +80,14 @@ async fn run() -> Result<()> {
Subcommands::Updates(_) => {
print_res!(single pkgsite, updates, views::updates::UpdatesView);
}
Subcommands::Files(Files {
arch,
repo,
package,
version,
}) => {
print_res!(single pkgsite, files, views::files::FilesView, &arch, &repo, &package, &version);
}
},
None => {
print_res!(single pkgsite, index, views::index::IndexView);
Expand Down
93 changes: 93 additions & 0 deletions src/views/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use pkgsite_lib::files::Files;
use std::fmt::Display;
use tabled::{
builder::Builder,
settings::{Alignment, Modify, Padding, Settings, Style, object::SegmentAll},
};

use pkgsite_tools::PADDING;

fn ls_perm(perm: &i32, ftype: &i16) -> String {
// see https://docs.rs/tar/latest/src/tar/entry_type.rs.html#70-87
let ftype = match ftype {
1 => 'l',
3 => 'c',
4 => 'b',
5 => 'd',
6 => 'p',
_ => '-',
};

let perm: String = format!("{perm:b}")
.chars()
.zip("rwxrwxrwx".chars())
.map(|(a, b)| if a == '1' { b } else { '-' })
.collect();

format!("{ftype}{perm}")
}

pub struct FilesView<'a> {
inner: &'a Files,
}

impl<'a> From<&'a Files> for FilesView<'a> {
fn from(inner: &'a Files) -> Self {
Self { inner }
}
}

impl Display for FilesView<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut file_matrix = Builder::default();
for row in &self.inner.files {
file_matrix.push_record(vec![
ls_perm(&row.perm, &row.ftype),
format!("{}({})", row.uname, row.uid),
format!("{}({})", row.gname, row.gid),
row.size.to_string(),
row.filename.clone().unwrap_or_default(),
]);
}

let table_settings = Settings::default().with(Style::blank()).with(
Modify::new(SegmentAll)
.with(Alignment::left())
.with(Padding::new(0, PADDING, 0, 0)),
);

write!(
f,
"Files in \"{}\" ({})
Repository: {}/{}
Package Time: {}
Size: {}
SHA256: {}
Installed Size: {}
Maintainer: {}{}{}

Files:
{}",
&self.inner.pkg.package,
&self.inner.pkg.version,
&self.inner.pkg.architecture,
&self.inner.pkg.repo,
&self.inner.pkg_debtime,
&self.inner.pkg.size,
&self.inner.pkg.sha256,
&self.inner.pkg.installed_size,
&self.inner.pkg.maintainer,
if self.inner.sodepends.is_empty() {
String::new()
} else {
format!("\nLibrary Depends: {}", &self.inner.sodepends.join(", "))
},
if self.inner.soprovides.is_empty() {
String::new()
} else {
format!("\nLibrary Provides: {}", &self.inner.soprovides.join(", "))
},
file_matrix.build().with(table_settings),
)
}
}
1 change: 1 addition & 0 deletions src/views/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod depends;
pub mod files;
pub mod index;
pub mod info;
pub mod rdepends;
Expand Down