Fix some clippy lints

This commit is contained in:
Nathan Fisher 2023-04-18 17:48:40 -04:00
parent 6037836f6b
commit 641eff3378
9 changed files with 60 additions and 71 deletions

View File

@ -34,6 +34,7 @@ pub struct Creator {
}
impl Creator {
#[allow(clippy::missing_panics_doc)]
pub fn new(path: &Path, specs: Specs) -> Result<Self, io::Error> {
let d = env::current_dir()?;
env::set_current_dir(path)?;
@ -74,7 +75,7 @@ impl Creator {
self.entries.is_empty()
}
pub fn create(self, outdir: &Path, sender: Sender<Message>) -> Result<(), Box<dyn Error>> {
pub fn create(self, outdir: &Path, sender: &Sender<Message>) -> Result<(), Box<dyn Error>> {
let d = env::current_dir()?;
let plist = Mutex::new(Plist::default());
let totalsize: AtomicUsize = 0.into();

View File

@ -66,21 +66,21 @@ impl Hooks {
}
fn makeinfo() -> Result<Output, InstallError> {
Command::new("makewhatis").output().map_err(|e| e.into())
Command::new("makewhatis").output().map_err(Into::into)
}
fn compile_schemas() -> Result<Output, InstallError> {
Command::new("glib-compile-schemas")
.arg("/usr/share/glib-2.0/schemas")
.output()
.map_err(|e| e.into())
.map_err(Into::into)
}
fn install_info(path: &str) -> Result<Output, InstallError> {
Command::new("install-info")
.arg(path)
.output()
.map_err(|e| e.into())
.map_err(Into::into)
}
impl Pinstall {
@ -93,6 +93,6 @@ impl Pinstall {
.arg(self.script.to_str().unwrap_or(""))
.env("HPK_ROOT", self.root.to_str().unwrap_or(""))
.output()
.map_err(|e| e.into())
.map_err(Into::into)
}
}

View File

@ -100,7 +100,7 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
}
Ok::<(), CreationError>(())
});
creator.create(&outdir, sender)?;
creator.create(&outdir, &sender)?;
match handle.join() {
Ok(_) => {
println!("Package created successfully");

View File

@ -1,5 +1,5 @@
#![allow(dead_code)]
pub use error::InstallError;
pub use error::Error;
use {
crate::{
@ -80,13 +80,12 @@ impl<T: io::Read> Installer<T> {
self,
hooks: &mut Vec<Hooks>,
sender: Sender<InstallMessage>,
) -> Result<Package, InstallError> {
) -> Result<Package, Error> {
let reader = Decoder::new(self.reader)?;
let mut archive = Archive::read(reader)?;
sender.send(InstallMessage::ArchiveRead)?;
let pr_node = match archive.pop("package.ron") {
Some(node) => node,
None => return Err(InstallError::MissingManifest),
let Some(pr_node) = archive.pop("package.ron") else {
return Err(Error::MissingManifest);
};
let mut buf = vec![];
pr_node.write(&mut buf)?;
@ -94,12 +93,12 @@ impl<T: io::Read> Installer<T> {
if let Some(ref users) = package.users {
users
.iter()
.for_each(|u| hooks.push((u.clone(), Some(self.root.to_path_buf())).into()));
.for_each(|u| hooks.push((u.clone(), Some(self.root.clone())).into()));
}
if let Some(ref groups) = package.groups {
groups
.iter()
.for_each(|g| hooks.push((g.clone(), Some(self.root.to_path_buf())).into()));
.for_each(|g| hooks.push((g.clone(), Some(self.root.clone())).into()));
}
let mut db_pkgdir = crate::get_dbdir(Some(self.root.clone()));
db_pkgdir.push(&package.name);
@ -120,11 +119,10 @@ impl<T: io::Read> Installer<T> {
pr_node.write(writer)?;
let root = &self.root;
let hooks = Mutex::new(hooks);
let s = sender.clone();
archive
.nodes
.par_iter()
.try_for_each_with(s, |sender, node| {
.try_for_each_with(sender, |sender, node| {
let mut path = root.clone();
let fpath = node.header.file_path()?;
if let Some(s) = node.header.prefix() {
@ -137,7 +135,7 @@ impl<T: io::Read> Installer<T> {
hooks
.lock()
.unwrap()
.push(Hooks::Info(fpath.to_str().unwrap().to_string()))
.push(Hooks::Info(fpath.to_str().unwrap().to_string()));
} else if s.contains("/share/glib-2.0/schemas") {
let mut h = hooks.lock().unwrap();
if !h.contains(&Hooks::GlibSchema) {
@ -157,14 +155,15 @@ impl<T: io::Read> Installer<T> {
mode: _,
size: _,
} => path == &fpath,
Entry::Link { path, target: _ } => path == &fpath,
Entry::Directory { path, mode: _ } => path == &fpath,
Entry::Link { path, target: _ } | Entry::Directory { path, mode: _ } => {
path == &fpath
}
})
.unwrap();
path = path.join(&fpath);
if let Some(parent) = path.parent() {
if !parent.exists() {
fs::create_dir_all(&parent)?;
fs::create_dir_all(parent)?;
}
}
if path.exists() {
@ -176,24 +175,20 @@ impl<T: io::Read> Installer<T> {
}
let msg = extract_entry(entry, node, path)?;
sender.send(msg)?;
Ok::<(), InstallError>(())
Ok::<(), Error>(())
})?;
Ok(package)
}
}
fn extract_entry(
entry: &Entry,
node: &Node,
path: PathBuf,
) -> Result<InstallMessage, InstallError> {
fn extract_entry(entry: &Entry, node: &Node, path: PathBuf) -> Result<InstallMessage, Error> {
match entry {
Entry::Directory { path: _, mode } => {
DirBuilder::new().mode(*mode).create(&path)?;
Ok(InstallMessage::DirectoryCreated(path))
}
Entry::Link { path: _, target } => {
os::unix::fs::symlink(&path, &target)?;
os::unix::fs::symlink(&path, target)?;
Ok(InstallMessage::LinkCreated(Link {
path,
target: target.clone(),
@ -215,7 +210,7 @@ fn extract_entry(
write!(sum, "{c:02x}")?;
}
if sha256sum != &sum {
return Err(InstallError::ChecksumMismatch);
return Err(Error::ChecksumMismatch);
}
let fd = File::options().mode(*mode).write(true).open(&path)?;
let mut writer = BufWriter::new(fd);
@ -225,7 +220,7 @@ fn extract_entry(
}
}
fn pop_appstream(archive: &mut Archive, db_pkgdir: &Path) -> Result<(), InstallError> {
fn pop_appstream(archive: &mut Archive, db_pkgdir: &Path) -> Result<(), Error> {
let appstream = archive.pop("appdata.xml");
if let Some(node) = appstream {
let mut appdatafile = db_pkgdir.to_path_buf();
@ -242,7 +237,7 @@ fn pop_pinstall(
hooks: &mut Vec<Hooks>,
pkgname: &str,
root: &Path,
) -> Result<(), InstallError> {
) -> Result<(), Error> {
let pinstall = archive.pop("postinstall.sh");
if let Some(node) = pinstall {
let mut path: PathBuf = ["/", "tmp", "hpk", pkgname].iter().collect();
@ -263,7 +258,6 @@ mod error {
use crate::{tar, Hooks};
use ron::error::SpannedError;
use std::{
error::Error,
fmt, io,
string::FromUtf8Error,
sync::{
@ -273,7 +267,7 @@ mod error {
};
#[derive(Debug)]
pub enum InstallError {
pub enum Error {
Fmt(fmt::Error),
IO(io::Error),
RonError(SpannedError),
@ -285,14 +279,14 @@ mod error {
Utf8,
}
impl fmt::Display for InstallError {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl Error for InstallError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Fmt(e) => Some(e),
Self::IO(e) => Some(e),
@ -304,49 +298,49 @@ mod error {
}
}
impl From<fmt::Error> for InstallError {
impl From<fmt::Error> for Error {
fn from(value: fmt::Error) -> Self {
Self::Fmt(value)
}
}
impl From<io::Error> for InstallError {
impl From<io::Error> for Error {
fn from(value: io::Error) -> Self {
Self::IO(value)
}
}
impl From<PoisonError<Sender<InstallMessage>>> for InstallError {
impl From<PoisonError<Sender<InstallMessage>>> for Error {
fn from(_value: PoisonError<Sender<InstallMessage>>) -> Self {
Self::MutexError
}
}
impl From<PoisonError<Vec<Hooks>>> for InstallError {
impl From<PoisonError<Vec<Hooks>>> for Error {
fn from(_value: PoisonError<Vec<Hooks>>) -> Self {
Self::MutexError
}
}
impl From<SendError<InstallMessage>> for InstallError {
impl From<SendError<InstallMessage>> for Error {
fn from(value: SendError<InstallMessage>) -> Self {
Self::SendError(value)
}
}
impl From<SpannedError> for InstallError {
impl From<SpannedError> for Error {
fn from(value: SpannedError) -> Self {
Self::RonError(value)
}
}
impl From<FromUtf8Error> for InstallError {
impl From<FromUtf8Error> for Error {
fn from(_value: FromUtf8Error) -> Self {
Self::Utf8
}
}
impl From<crate::tar::Error> for InstallError {
impl From<crate::tar::Error> for Error {
fn from(value: crate::tar::Error) -> Self {
Self::Tar(value)
}

View File

@ -6,7 +6,6 @@ use {
deku::DekuError,
sha2::{Digest, Sha256},
std::{
error::Error,
ffi::OsStr,
fmt::{self, Write},
fs,
@ -24,7 +23,7 @@ pub struct Item {
}
impl Item {
pub fn try_create(path: &Path) -> Result<Self, ItemError> {
pub fn try_create(path: &Path) -> Result<Self, Error> {
let path = fix_path(path);
let meta = fs::metadata(&path)?;
let filename = format!("{}", path.display());
@ -72,21 +71,21 @@ impl Item {
}
#[derive(Debug)]
pub enum ItemError {
pub enum Error {
Io(io::Error),
Fmt(fmt::Error),
Tar(TarError),
Deku(DekuError),
}
impl fmt::Display for ItemError {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl Error for ItemError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Io(e) => Some(e),
Self::Fmt(e) => Some(e),
@ -96,25 +95,25 @@ impl Error for ItemError {
}
}
impl From<io::Error> for ItemError {
impl From<io::Error> for Error {
fn from(value: io::Error) -> Self {
Self::Io(value)
}
}
impl From<fmt::Error> for ItemError {
impl From<fmt::Error> for Error {
fn from(value: fmt::Error) -> Self {
Self::Fmt(value)
}
}
impl From<TarError> for ItemError {
impl From<TarError> for Error {
fn from(value: TarError) -> Self {
Self::Tar(value)
}
}
impl From<DekuError> for ItemError {
impl From<DekuError> for Error {
fn from(value: DekuError) -> Self {
Self::Deku(value)
}

View File

@ -17,8 +17,8 @@ pub use {
creator::{CreationError, Creator, Message},
db::Database,
hooks::{Hooks, Pinstall},
installer::{InstallError, InstallMessage, Installer},
item::{Item, ItemError},
installer::{Error as InstallError, InstallMessage, Installer},
item::{Error as ItemError, Item},
package::{Arch, Dependency, Group, Package, Specs, User},
plist::{Entry, Plist},
repository::Repository,

View File

@ -34,9 +34,9 @@ pub enum Message {
}
impl Repository {
pub fn build(name: &str, url: &Url, sender: Sender<Message>) -> Result<Self, Box<dyn Error>> {
pub fn build(name: &str, url: &Url, sender: &Sender<Message>) -> Result<Self, Box<dyn Error>> {
let url = url.join("packages.ron.zstd")?;
let resp = ureq::get(&url.to_string())
let resp = ureq::get(url.as_ref())
.timeout(Duration::from_secs(10))
.call()?;
if let Some(val) = resp.header("Content-Length") {
@ -57,7 +57,7 @@ impl Repository {
let packages = ron::de::from_bytes(&buf)?;
Ok(Self {
name: name.to_string(),
base_url: url.clone(),
base_url: url,
packages,
})
}

View File

@ -1,3 +1,4 @@
#![allow(clippy::similar_names)]
use crate::tar::Error;
use deku::prelude::*;
use std::{
@ -131,9 +132,8 @@ impl Header {
for c in self.fname {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
Ok(s)
}
@ -153,9 +153,8 @@ impl Header {
for c in self.mode {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
let mode = u32::from_str_radix(&s, 8)?;
Ok(mode)
@ -166,9 +165,8 @@ impl Header {
for c in self.mode {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
let uid = u32::from_str_radix(&s, 8)?;
Ok(uid)
@ -179,9 +177,8 @@ impl Header {
for c in self.mode {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
let gid = u32::from_str_radix(&s, 8)?;
Ok(gid)
@ -192,9 +189,8 @@ impl Header {
for c in self.username {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
Ok(s)
}
@ -204,9 +200,8 @@ impl Header {
for c in self.groupname {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c))?;
}
write!(s, "{}", char::from(c))?;
}
Ok(s)
}
@ -239,9 +234,8 @@ impl Header {
for c in self.file_prefix {
if c == 0 {
break;
} else {
write!(s, "{}", char::from(c)).ok()?;
}
write!(s, "{}", char::from(c)).ok()?;
}
if s.is_empty() {
None

View File

@ -1,3 +1,4 @@
#![allow(clippy::similar_names)]
use crate::tar::{header::Owner, Error, FileType, Header};
use deku::prelude::*;
use std::{