Moved hpk-package all the way back into tree, fixed some clippy lints
This commit is contained in:
parent
b1fcbd1f9f
commit
1e7a02e33d
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -543,34 +543,22 @@ checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
[[package]]
|
||||
name = "hpk"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"hpk-package",
|
||||
"indicatif",
|
||||
"package-bootstrap",
|
||||
"rayon",
|
||||
"ron",
|
||||
"serde",
|
||||
"ureq",
|
||||
"url",
|
||||
"walkdir",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hpk-package"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git#e6f392bd7a91ffe3f0b080627e915ea458eade5a"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"clap",
|
||||
"deku",
|
||||
"indicatif",
|
||||
"libc",
|
||||
"package-bootstrap",
|
||||
"rayon",
|
||||
"ron",
|
||||
"serde",
|
||||
"sha2",
|
||||
"thiserror",
|
||||
"ureq",
|
||||
"url",
|
||||
"walkdir",
|
||||
"zstd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -21,12 +21,19 @@ path = "src/bootstrap.rs"
|
||||
required-features = ["bootstrap"]
|
||||
|
||||
[dependencies]
|
||||
hpk-package = { git = "https://git.hitchhiker-linux.org/jeang3nie/hpk-package.git" }
|
||||
deku = "0.16"
|
||||
libc = "0.2"
|
||||
rayon = "1.7"
|
||||
ron = "0.8"
|
||||
sha2 = "0.10"
|
||||
thiserror = "1.0"
|
||||
walkdir = "2.3"
|
||||
zstd = "0.12"
|
||||
|
||||
[dependencies.chrono]
|
||||
version = "0.4"
|
||||
features = ["serde"]
|
||||
|
||||
[dependencies.clap]
|
||||
version = "4.2"
|
||||
optional = true
|
||||
|
3
hpk-package/.gitignore
vendored
3
hpk-package/.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
/target
|
||||
/Cargo.lock
|
||||
tags
|
@ -1,29 +0,0 @@
|
||||
[package]
|
||||
name = "hpk-package"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-only"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
deku = "0.16"
|
||||
rayon = "1.7"
|
||||
ron = "0.8"
|
||||
sha2 = "0.10"
|
||||
walkdir = "2.3"
|
||||
thiserror = "1.0"
|
||||
libc = "0.2"
|
||||
|
||||
[dependencies.chrono]
|
||||
version = "0.4"
|
||||
features = ["serde"]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0"
|
||||
features = ["derive"]
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
strip = true
|
@ -1,12 +0,0 @@
|
||||
mod package;
|
||||
mod plist;
|
||||
pub mod tar;
|
||||
mod version;
|
||||
|
||||
pub use {
|
||||
deku,
|
||||
package::{Arch, Dependency, Group, Package, Specs, User},
|
||||
plist::*,
|
||||
ron, sha2,
|
||||
version::*,
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
use {
|
||||
crate::{Item, ItemError, Package, Plist, Specs},
|
||||
hpk_package::{deku::DekuError, tar, Entry},
|
||||
crate::{tar, Entry, Item, ItemError, Package, Plist, Specs},
|
||||
deku::DekuError,
|
||||
rayon::prelude::{IntoParallelRefIterator, ParallelIterator},
|
||||
std::{
|
||||
borrow::BorrowMut,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use {
|
||||
crate::{Arch, Package, Repository, Version},
|
||||
hpk_package::ron::{self, ser::PrettyConfig},
|
||||
rayon::prelude::*,
|
||||
ron::{self, ser::PrettyConfig},
|
||||
serde::{Deserialize, Serialize},
|
||||
std::{
|
||||
collections::HashMap,
|
||||
|
@ -1,7 +1,5 @@
|
||||
use hpk_package::{Group, User};
|
||||
|
||||
use {
|
||||
crate::InstallError,
|
||||
crate::{Group, InstallError, User},
|
||||
std::{
|
||||
path::PathBuf,
|
||||
process::{Command, Output},
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
mod cli;
|
||||
use {
|
||||
clap::ArgMatches,
|
||||
|
@ -2,13 +2,12 @@
|
||||
pub use error::InstallError;
|
||||
|
||||
use {
|
||||
crate::{Hooks, Pinstall},
|
||||
hpk_package::{
|
||||
sha2::{Digest, Sha256},
|
||||
crate::{
|
||||
tar::{Archive, Node},
|
||||
Entry, Group, Package, User,
|
||||
Entry, Group, Hooks, Package, Pinstall, User,
|
||||
},
|
||||
rayon::prelude::{IntoParallelRefIterator, ParallelIterator},
|
||||
sha2::{Digest, Sha256},
|
||||
std::{
|
||||
ffi::OsStr,
|
||||
fmt::Write as _,
|
||||
@ -102,60 +101,63 @@ impl<T: io::Read> Installer<T> {
|
||||
let package = &self.package;
|
||||
let hooks = Mutex::new(hooks);
|
||||
let s = sender.clone();
|
||||
archive.nodes.par_iter().try_for_each_with(s, |sender, node| {
|
||||
let mut path = path.clone();
|
||||
let fpath = node.header.file_path()?;
|
||||
if let Some(s) = node.header.prefix() {
|
||||
if s.contains("/share/man/") {
|
||||
let mut h = hooks.lock().unwrap();
|
||||
if !h.contains(&Hooks::Man) {
|
||||
h.push(Hooks::Man);
|
||||
}
|
||||
} else if s.contains("/share/info") {
|
||||
hooks
|
||||
.lock()
|
||||
.unwrap()
|
||||
.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) {
|
||||
h.push(Hooks::GlibSchema);
|
||||
archive
|
||||
.nodes
|
||||
.par_iter()
|
||||
.try_for_each_with(s, |sender, node| {
|
||||
let mut path = path.clone();
|
||||
let fpath = node.header.file_path()?;
|
||||
if let Some(s) = node.header.prefix() {
|
||||
if s.contains("/share/man/") {
|
||||
let mut h = hooks.lock().unwrap();
|
||||
if !h.contains(&Hooks::Man) {
|
||||
h.push(Hooks::Man);
|
||||
}
|
||||
} else if s.contains("/share/info") {
|
||||
hooks
|
||||
.lock()
|
||||
.unwrap()
|
||||
.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) {
|
||||
h.push(Hooks::GlibSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Match up a package entry with a tar node
|
||||
let entry = package
|
||||
.plist
|
||||
.entries
|
||||
.iter()
|
||||
.find(|&x| match x {
|
||||
Entry::File {
|
||||
path,
|
||||
sha256sum: _,
|
||||
mode: _,
|
||||
size: _,
|
||||
} => path == &fpath,
|
||||
Entry::Link { path, target: _ } => path == &fpath,
|
||||
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)?;
|
||||
// Match up a package entry with a tar node
|
||||
let entry = package
|
||||
.plist
|
||||
.entries
|
||||
.iter()
|
||||
.find(|&x| match x {
|
||||
Entry::File {
|
||||
path,
|
||||
sha256sum: _,
|
||||
mode: _,
|
||||
size: _,
|
||||
} => path == &fpath,
|
||||
Entry::Link { path, target: _ } => path == &fpath,
|
||||
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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
if path.exists() {
|
||||
if path.is_dir() {
|
||||
fs::remove_dir(&path)?;
|
||||
} else if path.is_symlink() || path.is_file() {
|
||||
fs::remove_file(&path)?;
|
||||
if path.exists() {
|
||||
if path.is_dir() {
|
||||
fs::remove_dir(&path)?;
|
||||
} else if path.is_symlink() || path.is_file() {
|
||||
fs::remove_file(&path)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
let msg = extract_entry(entry, node, path)?;
|
||||
sender.send(msg)?;
|
||||
Ok::<(), InstallError>(())
|
||||
})?;
|
||||
let msg = extract_entry(entry, node, path)?;
|
||||
sender.send(msg)?;
|
||||
Ok::<(), InstallError>(())
|
||||
})?;
|
||||
Ok(hooks.into_inner()?)
|
||||
}
|
||||
|
||||
@ -252,8 +254,8 @@ fn pop_pinstall(
|
||||
}
|
||||
|
||||
mod error {
|
||||
use crate::Hooks;
|
||||
use hpk_package::tar;
|
||||
use super::InstallMessage;
|
||||
use crate::{tar, Hooks};
|
||||
use std::{
|
||||
error::Error,
|
||||
fmt, io,
|
||||
@ -263,7 +265,6 @@ mod error {
|
||||
PoisonError,
|
||||
},
|
||||
};
|
||||
use super::InstallMessage;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InstallError {
|
||||
@ -331,8 +332,8 @@ mod error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hpk_package::tar::Error> for InstallError {
|
||||
fn from(value: hpk_package::tar::Error) -> Self {
|
||||
impl From<crate::tar::Error> for InstallError {
|
||||
fn from(value: crate::tar::Error) -> Self {
|
||||
Self::Tar(value)
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
use hpk_package::{
|
||||
use {
|
||||
crate::{
|
||||
tar::{Error as TarError, Node, Owner},
|
||||
Entry,
|
||||
},
|
||||
deku::DekuError,
|
||||
sha2::{Digest, Sha256},
|
||||
tar::{Error as TarError, Node, Owner},
|
||||
Entry,
|
||||
};
|
||||
use std::{
|
||||
error::Error,
|
||||
ffi::OsStr,
|
||||
fmt::{self, Write},
|
||||
fs,
|
||||
io::{self, Read},
|
||||
os::unix::fs::MetadataExt,
|
||||
path::{Path, PathBuf},
|
||||
std::{
|
||||
error::Error,
|
||||
ffi::OsStr,
|
||||
fmt::{self, Write},
|
||||
fs,
|
||||
io::{self, Read},
|
||||
os::unix::fs::MetadataExt,
|
||||
path::{Path, PathBuf},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -1,10 +1,15 @@
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
#![allow(clippy::must_use_candidate, clippy::missing_errors_doc)]
|
||||
mod creator;
|
||||
mod db;
|
||||
mod hooks;
|
||||
mod installer;
|
||||
mod item;
|
||||
mod package;
|
||||
mod plist;
|
||||
mod repository;
|
||||
pub mod tar;
|
||||
mod version;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
@ -12,10 +17,12 @@ pub use {
|
||||
creator::{CreationError, Creator, Message},
|
||||
db::Database,
|
||||
hooks::{Hooks, Pinstall},
|
||||
hpk_package::{tar, Arch, Dependency, GitRev, Package, Plist, Rapid, SemVer, Specs, Version},
|
||||
installer::{InstallError, InstallMessage, Installer},
|
||||
item::{Item, ItemError},
|
||||
package::{Arch, Dependency, Group, Package, Specs, User},
|
||||
plist::{Entry, Plist},
|
||||
repository::Repository,
|
||||
version::{GitRev, Rapid, SemVer, Version},
|
||||
};
|
||||
|
||||
const DB: [&str; 4] = ["var", "db", "hpk", "db.ron.zstd"];
|
||||
|
@ -1,6 +1,5 @@
|
||||
use {
|
||||
crate::Package,
|
||||
hpk_package::ron,
|
||||
rayon::prelude::*,
|
||||
serde::{Deserialize, Serialize},
|
||||
std::{
|
||||
|
@ -2,7 +2,7 @@ use crate::tar::Error;
|
||||
use deku::prelude::*;
|
||||
use std::{
|
||||
env,
|
||||
ffi::CStr,
|
||||
ffi::{CStr, OsStr},
|
||||
fmt::{self, Write},
|
||||
fs::{self, Metadata},
|
||||
io,
|
||||
@ -39,8 +39,6 @@ where
|
||||
return FileType::Char;
|
||||
} else if file_type.is_block_device() {
|
||||
return FileType::Block;
|
||||
} else if file_type.is_fifo() {
|
||||
return FileType::FIFO;
|
||||
} else if file_type.is_symlink() {
|
||||
return FileType::Symlink;
|
||||
} else if file_type.is_file() {
|
||||
@ -122,7 +120,7 @@ impl Header {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
///
|
||||
/// let header = Header::new("test/1.txt").unwrap();
|
||||
/// let filename = header.filename().unwrap();
|
||||
@ -144,7 +142,7 @@ impl Header {
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
///
|
||||
/// let header = Header::new("test/1.txt").unwrap();
|
||||
/// let mode = header.mode().unwrap();
|
||||
@ -230,7 +228,7 @@ impl Header {
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
///
|
||||
/// let header = Header::new("test/1.txt").unwrap();
|
||||
/// let prefix = header.prefix().unwrap();
|
||||
@ -239,10 +237,10 @@ impl Header {
|
||||
pub fn prefix(&self) -> Option<String> {
|
||||
let mut s = String::new();
|
||||
for c in self.file_prefix {
|
||||
if c != 0 {
|
||||
write!(s, "{}", char::from(c)).ok()?;
|
||||
} else {
|
||||
if c == 0 {
|
||||
break;
|
||||
} else {
|
||||
write!(s, "{}", char::from(c)).ok()?;
|
||||
}
|
||||
}
|
||||
if s.is_empty() {
|
||||
@ -257,7 +255,7 @@ impl Header {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
/// use std::path::PathBuf;
|
||||
///
|
||||
/// let header = Header::new("test/1.txt").unwrap();
|
||||
@ -274,6 +272,7 @@ impl Header {
|
||||
Ok(path)
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_panics_doc)]
|
||||
pub fn new(filename: &str) -> Result<Self, Error> {
|
||||
let mut header = Header::default();
|
||||
let meta = fs::symlink_metadata(filename)?;
|
||||
@ -282,7 +281,7 @@ impl Header {
|
||||
// revision allows storing the path prefix separately, with 100 bytes
|
||||
// reserved for the file name and 150 bytes for the rest of the path.
|
||||
let path = PathBuf::from(&filename);
|
||||
let name = match path.file_name().and_then(|n| n.to_str()) {
|
||||
let name = match path.file_name().and_then(OsStr::to_str) {
|
||||
Some(n) => n.to_string(),
|
||||
None => {
|
||||
return Err(Error::Io(io::Error::new(
|
||||
@ -326,7 +325,7 @@ impl Header {
|
||||
/* TODO: Find better way to get username */
|
||||
let key = "USER";
|
||||
if let Ok(val) = env::var(key) {
|
||||
header.username[..val.len()].copy_from_slice(val.as_bytes())
|
||||
header.username[..val.len()].copy_from_slice(val.as_bytes());
|
||||
}
|
||||
/* TODO: Find way to get groupname */
|
||||
|
||||
@ -336,6 +335,7 @@ impl Header {
|
||||
Ok(header)
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_panics_doc)]
|
||||
pub fn new_from_meta(
|
||||
filename: &str,
|
||||
meta: &Metadata,
|
||||
@ -347,7 +347,7 @@ impl Header {
|
||||
// revision allows storing the path prefix separately, with 100 bytes
|
||||
// reserved for the file name and 150 bytes for the rest of the path.
|
||||
let path = PathBuf::from(&filename);
|
||||
let name = match path.file_name().and_then(|n| n.to_str()) {
|
||||
let name = match path.file_name().and_then(OsStr::to_str) {
|
||||
Some(n) => n.to_string(),
|
||||
None => {
|
||||
return Err(Error::Io(io::Error::new(
|
||||
@ -403,7 +403,7 @@ impl Header {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
/// let header = Header::default();
|
||||
/// if !header.validate_magic() {
|
||||
/// println!("Magic value is invalid");
|
||||
@ -418,7 +418,7 @@ impl Header {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
/// let header = Header::default();
|
||||
/// if header.validate_checksum().unwrap() {
|
||||
/// println!("Checksum is valid");
|
||||
@ -440,7 +440,7 @@ impl Header {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Header;
|
||||
/// use hpk::tar::Header;
|
||||
/// let mut header = Header::default();
|
||||
///
|
||||
/// /* Fill in header information */
|
@ -4,7 +4,7 @@ use std::{
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator, IndexedParallelIterator};
|
||||
use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||
|
||||
mod error;
|
||||
mod header;
|
||||
@ -37,7 +37,7 @@ impl Archive {
|
||||
///
|
||||
/// ```
|
||||
/// use std::fs::File;
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
///
|
||||
/// let data = Archive::new("test/1.txt").unwrap();
|
||||
///
|
||||
@ -65,7 +65,7 @@ impl Archive {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
///
|
||||
/// let data = Archive::new("test/1.txt").unwrap();
|
||||
/// ```
|
||||
@ -81,7 +81,7 @@ impl Archive {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
///
|
||||
/// let mut data = Archive::new("test/1.txt").unwrap();
|
||||
/// data.append("test/1.txt").unwrap();
|
||||
@ -98,7 +98,7 @@ impl Archive {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
///
|
||||
/// Archive::open("test/1.tar").unwrap();
|
||||
/// ```
|
||||
@ -111,9 +111,9 @@ impl Archive {
|
||||
/// Read a tar archive from anything which implements `io::Read`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
/// use std::{fs::File, io::BufReader};
|
||||
///
|
||||
/// let file = File::open("test/1.tar").unwrap();
|
||||
@ -135,7 +135,7 @@ impl Archive {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
///
|
||||
/// let mut data = Archive::new("test/1.tar").unwrap();
|
||||
/// data.remove("test/1.tar").unwrap();
|
||||
@ -143,7 +143,11 @@ impl Archive {
|
||||
pub fn remove(&mut self, filename: &str) -> Result<bool, Error> {
|
||||
let mut name = [0u8; 100];
|
||||
name[..filename.len()].copy_from_slice(filename.as_bytes());
|
||||
if let Some(i) = &self.nodes.par_iter().position_any(|x| x.header.fname == name) {
|
||||
if let Some(i) = &self
|
||||
.nodes
|
||||
.par_iter()
|
||||
.position_any(|x| x.header.fname == name)
|
||||
{
|
||||
self.nodes.remove(*i);
|
||||
return Ok(true);
|
||||
}
|
||||
@ -156,21 +160,24 @@ impl Archive {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use hpk_package::tar::Archive;
|
||||
/// use hpk::tar::Archive;
|
||||
/// let archive = Archive::new("test/1.txt").unwrap();
|
||||
/// let node = archive.get("test/1.txt");
|
||||
/// assert!(node.is_some());
|
||||
/// ```
|
||||
pub fn get(&self, filename: &str) -> Option<Node> {
|
||||
self.nodes.par_iter().find_any(|x| {
|
||||
x.header.file_path() == Ok(PathBuf::from(filename))
|
||||
}).cloned()
|
||||
self.nodes
|
||||
.par_iter()
|
||||
.find_any(|x| x.header.file_path() == Ok(PathBuf::from(filename)))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn pop(&mut self, filename: &str) -> Option<Node> {
|
||||
if let Some(i) = self.nodes.par_iter().position_any(|x| {
|
||||
x.header.file_path() == Ok(PathBuf::from(filename))
|
||||
}) {
|
||||
if let Some(i) = self
|
||||
.nodes
|
||||
.par_iter()
|
||||
.position_any(|x| x.header.file_path() == Ok(PathBuf::from(filename)))
|
||||
{
|
||||
let node = self.nodes.get(i).cloned();
|
||||
self.nodes.remove(i);
|
||||
return node;
|
@ -34,7 +34,7 @@ impl Node {
|
||||
Ok(written)
|
||||
}
|
||||
|
||||
/// Read a TarNode in from a file or something with a ``std::io::Read`` trait.
|
||||
/// Read a `Node` in from a file or something with a ``std::io::Read`` trait.
|
||||
pub fn read<T: io::Read>(mut input: T) -> Result<Self, Error> {
|
||||
let mut h = vec![0u8; 512];
|
||||
input.read_exact(&mut h)?;
|
||||
@ -57,7 +57,7 @@ impl Node {
|
||||
})
|
||||
}
|
||||
|
||||
/// Open and read a file from the ``filename`` argument to a TarNode.
|
||||
/// Open and read a file from the ``filename`` argument to a `Node`.
|
||||
pub fn read_file_to_tar(filename: &str) -> Result<Self, Error> {
|
||||
let header = Header::new(filename)?;
|
||||
if header.link_indicator[0] != FileType::Normal as u8 {
|
@ -11,9 +11,9 @@ pub use {gitrev::GitRev, rapid::Rapid, semver::SemVer};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
/// An enum representing the most common versioning schemes.
|
||||
/// Each scheme must implement Eq and Ord with itself, and
|
||||
/// may optionally implement PartialEq and PartialOrd with
|
||||
/// other schemes. Number, Rapid, and SemVer do this, while
|
||||
/// Each scheme must implement `Eq` and `Ord` with itself, and
|
||||
/// may optionally implement `PartialEq` and `PartialOrd` with
|
||||
/// other schemes. `Number`, `Rapid`, and `SemVer` do this, while
|
||||
/// Git can only compare with itself.
|
||||
pub enum Version {
|
||||
/// A single replease number, as in Firefox 102
|
@ -168,27 +168,47 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn rapid_num_eq() {
|
||||
let rapid = Rapid { major: 42, minor: 0 };
|
||||
let rapid = Rapid {
|
||||
major: 42,
|
||||
minor: 0,
|
||||
};
|
||||
assert_eq!(rapid, 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rapid_num_gt() {
|
||||
let rapid = Rapid { major: 1, minor: 42 };
|
||||
let rapid = Rapid {
|
||||
major: 1,
|
||||
minor: 42,
|
||||
};
|
||||
assert!(rapid > 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rapid_semver_eq() {
|
||||
let rapid = Rapid { major: 42, minor: 69 };
|
||||
let semver = SemVer { major: 42, minor: 69, patch: 0 };
|
||||
let rapid = Rapid {
|
||||
major: 42,
|
||||
minor: 69,
|
||||
};
|
||||
let semver = SemVer {
|
||||
major: 42,
|
||||
minor: 69,
|
||||
patch: 0,
|
||||
};
|
||||
assert_eq!(rapid, semver);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rapid_semver_lt() {
|
||||
let rapid = Rapid { major: 42, minor: 69 };
|
||||
let semver = SemVer { major: 42, minor: 69, patch: 1 };
|
||||
let rapid = Rapid {
|
||||
major: 42,
|
||||
minor: 69,
|
||||
};
|
||||
let semver = SemVer {
|
||||
major: 42,
|
||||
minor: 69,
|
||||
patch: 1,
|
||||
};
|
||||
assert!(rapid < semver);
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user