Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lib/rename regular to normal #1100

Merged
merged 7 commits into from
Oct 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion cli/benches/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use portable_network_archive::{cli, command};
use test::Bencher;

#[bench]
fn regular(b: &mut Bencher) {
fn normal(b: &mut Bencher) {
b.iter(|| {
command::entry(cli::Cli::parse_from([
"pna",
Expand Down
4 changes: 2 additions & 2 deletions cli/src/command/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
utils::{GlobPatterns, PathPartExt},
};
use clap::{Parser, ValueHint};
use pna::RegularEntry;
use pna::NormalEntry;
use std::{
io,
path::PathBuf,
Expand Down Expand Up @@ -75,7 +75,7 @@ fn archive_chmod(args: ChmodCommand) -> io::Result<()> {
}

#[inline]
fn transform_entry<T>(entry: RegularEntry<T>, mode: Mode) -> RegularEntry<T> {
fn transform_entry<T>(entry: NormalEntry<T>, mode: Mode) -> NormalEntry<T> {
let metadata = entry.metadata().clone();
let permission = metadata.permission().map(|p| {
let mode = mode.apply_to(p.permissions());
Expand Down
4 changes: 2 additions & 2 deletions cli/src/command/chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
utils::{GlobPatterns, PathPartExt},
};
use clap::{Parser, ValueHint};
use pna::RegularEntry;
use pna::NormalEntry;
use std::ops::Not;
use std::{io, path::PathBuf, str::FromStr};

Expand Down Expand Up @@ -74,7 +74,7 @@ fn archive_chown(args: ChownCommand) -> io::Result<()> {
}

#[inline]
fn transform_entry<T>(entry: RegularEntry<T>, owner: &Owner) -> RegularEntry<T> {
fn transform_entry<T>(entry: NormalEntry<T>, owner: &Owner) -> NormalEntry<T> {
let metadata = entry.metadata().clone();
let permission = metadata.permission().map(|p| {
let user = owner.user();
Expand Down
44 changes: 22 additions & 22 deletions cli/src/command/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{
};
use normalize_path::*;
use pna::{
prelude::*, Archive, EntryBuilder, EntryName, EntryPart, EntryReference, ReadEntry,
RegularEntry, SolidEntryBuilder, WriteOptions, MIN_CHUNK_BYTES_SIZE, PNA_HEADER,
prelude::*, Archive, EntryBuilder, EntryName, EntryPart, EntryReference, NormalEntry,
ReadEntry, SolidEntryBuilder, WriteOptions, MIN_CHUNK_BYTES_SIZE, PNA_HEADER,
};
use std::{
env::temp_dir,
Expand Down Expand Up @@ -115,7 +115,7 @@ pub(crate) fn create_entry(
keep_options,
owner_options,
}: CreateOptions,
) -> io::Result<RegularEntry> {
) -> io::Result<NormalEntry> {
if path.is_symlink() {
let source = fs::read_link(path)?;
let entry = EntryBuilder::new_symbolic_link(
Expand Down Expand Up @@ -363,9 +363,9 @@ pub(crate) trait TransformStrategy {
where
W: Write,
T: AsRef<[u8]>,
F: FnMut(io::Result<RegularEntry<T>>) -> io::Result<Option<RegularEntry<T>>>,
RegularEntry<T>: From<RegularEntry>,
RegularEntry<T>: Entry;
F: FnMut(io::Result<NormalEntry<T>>) -> io::Result<Option<NormalEntry<T>>>,
NormalEntry<T>: From<NormalEntry>,
NormalEntry<T>: Entry;
}

pub(crate) struct TransformStrategyUnSolid;
Expand All @@ -380,9 +380,9 @@ impl TransformStrategy for TransformStrategyUnSolid {
where
W: Write,
T: AsRef<[u8]>,
F: FnMut(io::Result<RegularEntry<T>>) -> io::Result<Option<RegularEntry<T>>>,
RegularEntry<T>: From<RegularEntry>,
RegularEntry<T>: Entry,
F: FnMut(io::Result<NormalEntry<T>>) -> io::Result<Option<NormalEntry<T>>>,
NormalEntry<T>: From<NormalEntry>,
NormalEntry<T>: Entry,
{
match read_entry? {
ReadEntry::Solid(s) => {
Expand All @@ -393,7 +393,7 @@ impl TransformStrategy for TransformStrategyUnSolid {
}
Ok(())
}
ReadEntry::Regular(n) => {
ReadEntry::Normal(n) => {
if let Some(entry) = transformer(Ok(n))? {
archive.add_entry(entry)?;
}
Expand All @@ -415,9 +415,9 @@ impl TransformStrategy for TransformStrategyKeepSolid {
where
W: Write,
T: AsRef<[u8]>,
F: FnMut(io::Result<RegularEntry<T>>) -> io::Result<Option<RegularEntry<T>>>,
RegularEntry<T>: From<RegularEntry>,
RegularEntry<T>: Entry,
F: FnMut(io::Result<NormalEntry<T>>) -> io::Result<Option<NormalEntry<T>>>,
NormalEntry<T>: From<NormalEntry>,
NormalEntry<T>: Entry,
{
match read_entry? {
ReadEntry::Solid(s) => {
Expand All @@ -438,7 +438,7 @@ impl TransformStrategy for TransformStrategyKeepSolid {
archive.add_entry(builder.build()?)?;
Ok(())
}
ReadEntry::Regular(n) => {
ReadEntry::Normal(n) => {
if let Some(entry) = transformer(Ok(n))? {
archive.add_entry(entry)?;
}
Expand Down Expand Up @@ -478,7 +478,7 @@ pub(crate) fn run_process_archive<'p, Provider, F>(
) -> io::Result<()>
where
Provider: FnMut() -> Option<&'p str>,
F: FnMut(io::Result<RegularEntry>) -> io::Result<()>,
F: FnMut(io::Result<NormalEntry>) -> io::Result<()>,
{
let password = password_provider();
run_read_entries(archive_provider, |entry| match entry? {
Expand All @@ -488,7 +488,7 @@ where
}
Ok(())
}
ReadEntry::Regular(regular) => processor(Ok(regular)),
ReadEntry::Normal(regular) => processor(Ok(regular)),
})
}

Expand Down Expand Up @@ -550,7 +550,7 @@ pub(crate) fn run_entries<'p, P, Provider, F>(
where
P: AsRef<Path>,
Provider: FnMut() -> Option<&'p str>,
F: FnMut(io::Result<RegularEntry<std::borrow::Cow<[u8]>>>) -> io::Result<()>,
F: FnMut(io::Result<NormalEntry<std::borrow::Cow<[u8]>>>) -> io::Result<()>,
{
let password = password_provider();
run_read_entries_mem(path, |entry| {
Expand All @@ -560,7 +560,7 @@ where
processor(r.map(Into::into))?;
}
}
ReadEntry::Regular(r) => processor(Ok(r))?,
ReadEntry::Normal(r) => processor(Ok(r))?,
}
Ok(())
})
Expand All @@ -579,8 +579,8 @@ where
P: AsRef<Path>,
Provider: FnMut() -> Option<&'p str>,
F: FnMut(
io::Result<RegularEntry<std::borrow::Cow<[u8]>>>,
) -> io::Result<Option<RegularEntry<std::borrow::Cow<[u8]>>>>,
io::Result<NormalEntry<std::borrow::Cow<[u8]>>>,
) -> io::Result<Option<NormalEntry<std::borrow::Cow<[u8]>>>>,
Transform: TransformStrategy,
{
let password = password_provider();
Expand Down Expand Up @@ -633,7 +633,7 @@ where
O: AsRef<Path>,
P: AsRef<Path>,
Provider: FnMut() -> Option<&'p str>,
F: FnMut(io::Result<RegularEntry>) -> io::Result<Option<RegularEntry>>,
F: FnMut(io::Result<NormalEntry>) -> io::Result<Option<NormalEntry>>,
Transform: TransformStrategy,
{
let password = password_provider();
Expand Down Expand Up @@ -664,7 +664,7 @@ pub(crate) fn run_entries<'p, P, Provider, F>(
where
P: AsRef<Path>,
Provider: FnMut() -> Option<&'p str>,
F: FnMut(io::Result<RegularEntry>) -> io::Result<()>,
F: FnMut(io::Result<NormalEntry>) -> io::Result<()>,
{
let path = path.as_ref();
let provider = PathArchiveProvider(path);
Expand Down
6 changes: 3 additions & 3 deletions cli/src/command/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
utils::{self, fmt::DurationDisplay, GlobPatterns},
};
use clap::{ArgGroup, Parser, ValueHint};
use pna::{prelude::*, DataKind, EntryReference, Permission, ReadOptions, RegularEntry};
use pna::{prelude::*, DataKind, EntryReference, NormalEntry, Permission, ReadOptions};
use rayon::ThreadPoolBuilder;
#[cfg(target_os = "macos")]
use std::os::macos::fs::FileTimesExt;
Expand Down Expand Up @@ -202,7 +202,7 @@ where
.build()
.map_err(io::Error::other)?;

let mut hard_link_entries = Vec::<RegularEntry>::new();
let mut hard_link_entries = Vec::<NormalEntry>::new();

let (tx, rx) = std::sync::mpsc::channel();
run_entries(path, password_provider, |entry| {
Expand Down Expand Up @@ -237,7 +237,7 @@ where
}

pub(crate) fn extract_entry<T>(
item: RegularEntry<T>,
item: NormalEntry<T>,
password: Option<&str>,
OutputOption {
overwrite,
Expand Down
12 changes: 6 additions & 6 deletions cli/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use clap::{
ArgGroup, Parser,
};
use pna::{
prelude::*, Compression, DataKind, Encryption, ExtendedAttribute, RawChunk, ReadEntry,
ReadOptions, RegularEntry, SolidHeader,
prelude::*, Compression, DataKind, Encryption, ExtendedAttribute, NormalEntry, RawChunk,
ReadEntry, ReadOptions, SolidHeader,
};
use rayon::prelude::*;
#[cfg(feature = "memmap")]
Expand Down Expand Up @@ -98,7 +98,7 @@ struct TableRow {

impl<T>
TryFrom<(
&RegularEntry<T>,
&NormalEntry<T>,
Option<&str>,
SystemTime,
Option<&SolidHeader>,
Expand All @@ -113,7 +113,7 @@ where
#[inline]
fn try_from(
(entry, password, now, solid, numeric_owner): (
&RegularEntry<T>,
&NormalEntry<T>,
Option<&str>,
SystemTime,
Option<&SolidHeader>,
Expand Down Expand Up @@ -266,7 +266,7 @@ pub(crate) fn run_list_archive(
ReadEntry::Solid(_) => {
log::warn!("This archive contain solid mode entry. if you need to show it use --solid option.");
}
ReadEntry::Regular(item) => {
ReadEntry::Normal(item) => {
entries.push((&item, password, now, None, args.numeric_owner).try_into()?)
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ pub(crate) fn run_list_archive_mem(
ReadEntry::Solid(_) => {
log::warn!("This archive contain solid mode entry. if you need to show it use --solid option.");
}
ReadEntry::Regular(item) => {
ReadEntry::Normal(item) => {
entries.push((&item, password, now, None, args.numeric_owner).try_into()?)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/command/strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
utils::PathPartExt,
};
use clap::{Args, Parser, ValueHint};
use pna::{prelude::*, Metadata, RawChunk, RegularEntry};
use pna::{prelude::*, Metadata, NormalEntry, RawChunk};
use std::{io, path::PathBuf};

#[derive(Args, Clone, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -71,7 +71,7 @@ fn strip_metadata(args: StripCommand) -> io::Result<()> {
}

#[inline]
fn strip_entry_metadata<T>(mut entry: RegularEntry<T>, options: &StripOptions) -> RegularEntry<T>
fn strip_entry_metadata<T>(mut entry: NormalEntry<T>, options: &StripOptions) -> NormalEntry<T>
where
T: Clone,
RawChunk<T>: Chunk,
Expand Down
6 changes: 3 additions & 3 deletions cli/src/command/xattr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
use base64::Engine;
use clap::{Parser, ValueHint};
use indexmap::IndexMap;
use pna::RegularEntry;
use pna::NormalEntry;
use std::{
fmt::{Display, Formatter, Write},
io,
Expand Down Expand Up @@ -219,11 +219,11 @@ fn archive_set_xattr(args: SetXattrCommand) -> io::Result<()> {

#[inline]
fn transform_entry<T>(
entry: RegularEntry<T>,
entry: NormalEntry<T>,
name: Option<&str>,
value: &[u8],
remove: Option<&str>,
) -> RegularEntry<T> {
) -> NormalEntry<T> {
let mut xattrs = entry
.xattrs()
.iter()
Expand Down
6 changes: 3 additions & 3 deletions cli/src/ext.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::chunk::{self, Ace};
use pna::{prelude::*, RawChunk, RegularEntry};
use pna::{prelude::*, NormalEntry, RawChunk};
use std::io;

pub(crate) trait RegularEntryExt {
pub(crate) trait NormalEntryExt {
fn acl(&self) -> io::Result<Vec<Ace>>;
}

impl<T> RegularEntryExt for RegularEntry<T>
impl<T> NormalEntryExt for NormalEntry<T>
where
RawChunk<T>: Chunk,
{
Expand Down
2 changes: 1 addition & 1 deletion lib/benches/create_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn bench_read_archive_from_slice(b: &mut Bencher, mut options: WriteOptionsBuild
let mut buf = Vec::with_capacity(1000);
match item.unwrap() {
ReadEntry::Solid(_) => (),
ReadEntry::Regular(item) => {
ReadEntry::Normal(item) => {
item.reader(ReadOptions::with_password(Some("password")))
.unwrap()
.read_to_end(&mut buf)
Expand Down
Loading