Skip to content
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
8 changes: 4 additions & 4 deletions src/uapi16/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<R: Read> Reader<R> {
/// Feeds the decoder until it takes a step other than [`Step::Input`].
fn pull(&mut self) -> Result<Step, Error> {
loop {
match self.decoder.step()? {
match self.decoder.process()? {
Step::Input => self.fill()?,
step => return Ok(step),
}
Expand All @@ -158,7 +158,7 @@ impl<R: Read> Reader<R> {
};
let input = input.map_err(|e| self.decoder.input_error(e))?;
if input.is_empty() {
self.decoder.end();
self.decoder.end_feed();
} else {
let taken = self.decoder.feed(input);
self.input.consume(taken);
Expand Down Expand Up @@ -242,11 +242,11 @@ impl<R: Read> FusedIterator for Reader<R> {}
/// text where it can. The writer refuses such a record.
///
/// ```
/// use uapi16::{FileObject, Name, Object, Order, Reader, RootObject, Writer};
/// use uapi16::{FileObject, NameBuf, Object, Order, Reader, RootObject, Writer};
///
/// let mut root = RootObject::default();
/// root.set_order(Some(Order::CodePoint));
/// let mut file = FileObject::new(Name::new("a")?);
/// let mut file = FileObject::new(NameBuf::new("a")?);
/// file.set_size(Some(3));
/// let mut writer = Writer::begin(Vec::new(), &root)?;
/// writer.file(&file)?;
Expand Down
7 changes: 4 additions & 3 deletions src/uapi16/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ impl ContentsObject {
/// and calls [`DataCheck::finish`] after the last one.
///
/// ```
/// use uapi16::{DataCheck, FileObject, Name, Sha256};
/// use uapi16::{DataCheck, FileObject, NameBuf, Sha256};
///
/// let mut object = FileObject::new(Name::new("hello.txt")?);
/// let mut object = FileObject::new(NameBuf::new("hello.txt")?);
/// object.set_size(Some(5));
/// object.set_sha256(Some(Sha256::digest(b"hello")));
/// let mut check = DataCheck::new(&object);
Expand Down Expand Up @@ -1190,6 +1190,7 @@ mod tests {
use super::*;
use crate::error::Problem;
use crate::testing::{json, manifest, read_whole, sequence, HELLO, TRAILER, WORLD};
use crate::NameBuf;
use std::cell::{Cell, RefCell};
use std::rc::Rc;

Expand Down Expand Up @@ -2451,7 +2452,7 @@ mod tests {
assert_eq!(check(&sized, b"hello").unwrap(), b"hello");
assert_eq!(check(&sized, b"world").unwrap_err().kind(), hash);
// An object that is all of its file without a hash of its own.
let mut whole = FileObject::new(Name::new("x").unwrap());
let mut whole = FileObject::new(NameBuf::new("x").unwrap());
whole.size = Some(5);
let mut contents = ContentsObject::new(ContentsSource::Implied);
contents.original_size = Some(5);
Expand Down
31 changes: 16 additions & 15 deletions src/uapi16/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use crate::object::{
};
use crate::strict::{FieldTable, Key, Members, Skip, Strict};
use crate::{
Features, Name, Order, Sha256, MAX_CONTENTS, MEDIA_TYPE, SIGNATURE_MEDIA_TYPE, TRAILER_MEDIA_TYPE, USER_NAMESPACE,
Features, Name, NameBuf, Order, Sha256, MAX_CONTENTS, MEDIA_TYPE, SIGNATURE_MEDIA_TYPE, TRAILER_MEDIA_TYPE,
USER_NAMESPACE,
};

/// The user and group ID that is -1 as an unsigned 32-bit integer,
Expand Down Expand Up @@ -260,7 +261,7 @@ impl Field {
/// draft and every other record a [`FileObject`].
struct Draft {
object: Box<FileObject>,
name: Option<Name>,
name: Option<NameBuf>,
/// The name as the record has it, when it is not a valid one.
invalid_name: Option<String>,
inode_type: Option<InodeType>,
Expand All @@ -281,7 +282,7 @@ impl Draft {
/// The draft of a record no member of which was read yet.
fn new() -> Draft {
Draft {
object: Box::new(FileObject::new(Name::ROOT)),
object: Box::new(FileObject::new(NameBuf::default())),
name: None,
invalid_name: None,
inode_type: None,
Expand All @@ -298,7 +299,7 @@ impl Draft {
if !self.object.name.is_root() {
return Some(self.object.name.as_str());
}
self.name.as_ref().map(Name::as_str).or(self.invalid_name.as_deref())
self.name.as_deref().map(Name::as_str).or(self.invalid_name.as_deref())
}

/// The fields of a partition, which are made when the first of them is
Expand Down Expand Up @@ -1488,7 +1489,7 @@ impl<'a> RecordDecoder<'a> {
Field::Name => {
if let Some(name) = self.string(field, value) {
match Name::new(name.as_ref()) {
Ok(name) => draft.name = Some(name),
Ok(name) => draft.name = Some(name.to_owned()),
Err(reason) => {
let subject = self.subject();
self.note_error(Problem::InvalidName, field, || {
Expand Down Expand Up @@ -1872,7 +1873,7 @@ impl<'a> Part<'a> for ContentsElement {
let name = Name::new(file.as_ref())
.map_err(|reason| Error::invalid_file_reference(subject, reason, &file));
if let Some(name) = decoder.note_err(name) {
contents.source = ContentsSource::File(name);
contents.source = ContentsSource::File(name.to_owned());
places += 1;
}
}
Expand Down Expand Up @@ -2272,7 +2273,7 @@ mod tests {
fn what_a_field_can_look_like() {
// An object says as little as its name.
let o = object(r#"{"name":"x"}"#);
assert_eq!(o, FileObject::new(Name::new("x").unwrap()));
assert_eq!(o, FileObject::new(NameBuf::new("x").unwrap()));
// A field that is null is not there. Fields this crate does not
// know are passed over, whatever they hold.
let nulls = concat!(
Expand Down Expand Up @@ -2505,7 +2506,7 @@ mod tests {
object.check_consistency(subject, contents_data.into_iter())
};
let file = |size: Option<u64>, contents: ContentsObject| {
let mut object = FileObject::new(Name::new("x").unwrap());
let mut object = FileObject::new(NameBuf::new("x").unwrap());
object.size = size;
object.contents = vec![contents];
object
Expand All @@ -2520,7 +2521,7 @@ mod tests {
);
let mut beyond = hello();
beyond.offset = 7;
let mut headers = ContentsObject::new(ContentsSource::File(Name::new("a").unwrap()));
let mut headers = ContentsObject::new(ContentsSource::File(NameBuf::new("a").unwrap()));
headers.http_headers = vec![("A".to_string(), "b".to_string())];
let mut empty = file(Some(3), hello());
empty.contents.clear();
Expand Down Expand Up @@ -2560,7 +2561,7 @@ mod tests {
#[test]
fn set_contents_with_an_offset_beyond_the_data() {
let file = |offset: u64, original_size: u64| {
let mut contents = ContentsObject::new(ContentsSource::File(Name::new("a").unwrap()));
let mut contents = ContentsObject::new(ContentsSource::File(NameBuf::new("a").unwrap()));
contents.set_offset(offset);
contents.set_original_size(Some(original_size));
contents
Expand All @@ -2573,7 +2574,7 @@ mod tests {
encoded.set_encoding(Some("gzip".to_string()));
encoded.set_original_size(Some(3));
encoded.set_offset(4);
let whole = ContentsObject::new(ContentsSource::File(Name::new("a").unwrap()));
let whole = ContentsObject::new(ContentsSource::File(NameBuf::new("a").unwrap()));
for (size, contents) in [
(None, vec![file(6, 5)]),
(Some(1), vec![file(6, 5)]),
Expand All @@ -2582,7 +2583,7 @@ mod tests {
(None, vec![whole, file(5, 4)]),
(None, vec![file(u64::MAX, 0)]),
] {
let mut object = FileObject::new(Name::new("x").unwrap());
let mut object = FileObject::new(NameBuf::new("x").unwrap());
object.set_size(size);
object.set_contents(contents);
assert_eq!(object.size(), size, "{:?}", object);
Expand Down Expand Up @@ -2948,9 +2949,9 @@ mod tests {
let hello: Option<Sha256> = HELLO.parse().ok();
let world: Option<Sha256> = WORLD.parse().ok();
let literal = || ContentsObject::new(ContentsSource::Literal(b"hello".to_vec()));
let file = || ContentsObject::new(ContentsSource::File(Name::new("a").unwrap()));
let file = || ContentsObject::new(ContentsSource::File(NameBuf::new("a").unwrap()));
let set = |size: Option<u64>, sha256: Option<Sha256>, contents: Vec<ContentsObject>| {
let mut object = FileObject::new(Name::new("x").unwrap());
let mut object = FileObject::new(NameBuf::new("x").unwrap());
object.set_size(size);
object.set_sha256(sha256);
object.set_contents(contents);
Expand Down Expand Up @@ -3136,7 +3137,7 @@ mod tests {
r#"{"name":"x","contents":[{"file":"","originalSize":5}]}"#,
ContentsObject {
original_size: Some(5),
..ContentsObject::new(ContentsSource::File(Name::ROOT))
..ContentsObject::new(ContentsSource::File(NameBuf::default()))
},
Field::File,
),
Expand Down
8 changes: 4 additions & 4 deletions src/uapi16/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
/// What `dir` has under `name`: the text of a regular file, or why it
/// has none.
fn text(dir: &PinnedDirectory, name: &str) -> Result<String, Opened> {
let (mut file, len) = dir.open(&Name::new(name).unwrap()).map_err(Opened::from)?;
let (mut file, len) = dir.open(Name::new(name).unwrap()).map_err(Opened::from)?;
let mut text = String::new();
file.read_to_string(&mut text).unwrap();
assert_eq!(text.len() as u64, len, "{}", name);
Expand Down Expand Up @@ -250,7 +250,7 @@ mod tests {
// itself, which the root file object names.
assert_eq!(text(&plain, "sub"), Err(Opened::NotRegular));
assert_eq!(
plain.open(&Name::ROOT).map(|_| ()).map_err(Opened::from),
plain.open(Name::ROOT).map(|_| ()).map_err(Opened::from),
Err(Opened::NotRegular)
);
assert_eq!(text(&plain, "missing"), Err(Opened::Errno(libc::ENOENT)));
Expand Down Expand Up @@ -303,7 +303,7 @@ mod tests {
};
for state in [EmptyPath::UNKNOWN, EmptyPath::MISSING] {
EMPTYPATH.store(state, Ordering::Relaxed);
let (handle, _) = directory.pin(&Name::new("file").unwrap()).unwrap();
let (handle, _) = directory.pin(Name::new("file").unwrap()).unwrap();
fs::rename(dir.join("file"), dir.join("moved")).unwrap();
fs::write(dir.join("file"), b"impostor").unwrap();
assert_eq!(read(&mut PinnedDirectory::reopen(&handle).unwrap()), "pinned");
Expand Down Expand Up @@ -340,7 +340,7 @@ mod tests {
assert_eq!(text(&directory, "fifo"), Err(Opened::NotRegular));
assert_eq!(text(&directory, "file").as_deref(), Ok("data"));
// The file is the one that was pinned, open for reading only.
let (file, len) = directory.open(&Name::new("file").unwrap()).unwrap();
let (file, len) = directory.open(Name::new("file").unwrap()).unwrap();
assert_eq!(len, 4);
let flags = rustix::fs::fcntl_getfl(&file).unwrap();
assert_eq!(flags & OFlags::RWMODE, OFlags::RDONLY);
Expand Down
22 changes: 11 additions & 11 deletions src/uapi16/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
//! against the manifest with a [`DataCheck`].
//!
//! A manifest that does not come through a [`Read`], such as one from an
//! async runtime, goes to a [`Decoder`] as it comes. [`Decoder::step`] says
//! what comes next. When it asks for more of the manifest with
//! async runtime, goes to a [`Decoder`] as it comes. [`Decoder::process`]
//! says what comes next. When it asks for more of the manifest with
//! [`Step::Input`], [`Decoder::feed`] takes the bytes that came, up to the
//! end of the record it reads, and returns how many it took. The others go
//! in with a later call. [`Decoder::end`] says that there are no more. The
//! other steps hand out the root file object, the objects after it, and
//! in with a later call. [`Decoder::end_feed`] says that there are no more.
//! The other steps hand out the root file object, the objects after it, and
//! the end of the manifest. A record ends where the next one starts, so an
//! object comes once the separator of the record after it was fed, or the
//! input ended, and the end of the manifest once the input ended. A step
Expand Down Expand Up @@ -137,7 +137,7 @@ pub use digest::{InvalidDigest, Sha256, Sha256Context};
pub use directory::PinnedDirectory;
pub use error::{DataProblem, Error, ErrorKind, Field, Problem, SourceProblem, UnsupportedData, ValidityProblem};
pub use features::{Features, Order, UnknownFeature};
pub use name::{Name, NameProblem};
pub use name::{Name, NameBuf, NameError, NameProblem};
pub use object::{
ContentsObject, ContentsSource, FatSerial, FileObject, FileSystemIdentity, FilledIn, GptPartition, InodeAttributes,
InodeType, InvalidFatSerial, InvalidMode, InvalidUuid, Mode, RootObject, SignatureObject, UnknownInodeType, Uuid,
Expand Down Expand Up @@ -183,7 +183,7 @@ pub(crate) mod testing {
use super::blocking::READ_SIZE;
use super::object::{DosFlags, InodeFlags};
use super::{
ContentsObject, ContentsSource, Error, Features, FileObject, GptPartition, InodeType, Mode, Name, Object,
ContentsObject, ContentsSource, Error, Features, FileObject, GptPartition, InodeType, Mode, NameBuf, Object,
Reader, RootObject, Sha256, SignatureObject, Uuid, Validity, Writer, RECORD_END, RECORD_SEPARATOR,
};
use crate::strict::{ParseError, Skip, Strict};
Expand Down Expand Up @@ -302,9 +302,9 @@ pub(crate) mod testing {
/// The names of the full tree in which every directory has an entry
/// for each of `pieces`, down to `depth` components: every name of at
/// most `depth` components made of `pieces`, the root among them.
pub(crate) fn full_tree_names(pieces: &[&str], depth: usize) -> Vec<Name> {
let mut names = vec![Name::ROOT];
let mut level = vec![Name::ROOT];
pub(crate) fn full_tree_names(pieces: &[&str], depth: usize) -> Vec<NameBuf> {
let mut names = vec![NameBuf::default()];
let mut level = vec![NameBuf::default()];
for _ in 0..depth {
level = level
.iter()
Expand All @@ -327,8 +327,8 @@ pub(crate) mod testing {
writer.finish()
}

pub(crate) fn name(name: &str) -> Name {
Name::new(name).unwrap()
pub(crate) fn name(name: &str) -> NameBuf {
NameBuf::new(name).unwrap()
}

/// The records `writer` wrote after `root`, without the frame of
Expand Down
6 changes: 3 additions & 3 deletions src/uapi16/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs::Metadata;
use std::os::unix::fs::MetadataExt;

use crate::object::{FileObject, InodeType, Mode, UnknownInodeType};
use crate::{Features, Name};
use crate::{Features, NameBuf};

impl FileObject {
/// A file object for the file `name`, whose metadata is `meta`, with
Expand All @@ -27,7 +27,7 @@ impl FileObject {
/// It fails for a file whose type is not an inode type.
///
/// [`RootObject::recorded_features`]: crate::RootObject::recorded_features
pub fn from_metadata(name: Name, meta: &Metadata, features: Features) -> Result<FileObject, UnknownInodeType> {
pub fn from_metadata(name: NameBuf, meta: &Metadata, features: Features) -> Result<FileObject, UnknownInodeType> {
let mut object = FileObject::new(name);
object.inode_type = InodeType::try_from(meta.file_type())?;
let inode = &mut object.inode;
Expand Down Expand Up @@ -98,7 +98,7 @@ mod tests {
let mut writer = Writer::begin(Vec::new(), &root).unwrap();
for (name, path, inode_type) in &files {
let meta = fs::symlink_metadata(path).unwrap();
let mut object = FileObject::from_metadata(Name::new(*name).unwrap(), &meta, features).unwrap();
let mut object = FileObject::from_metadata(NameBuf::new(*name).unwrap(), &meta, features).unwrap();
assert_eq!(object.inode_type(), *inode_type, "{}", name);
let has = |feature: Features| features.contains(feature);
let mut inode = InodeAttributes {
Expand Down
Loading