Skip to content

Commit 571bad0

Browse files
authored
Serve package details (#83)
1 parent 80989fd commit 571bad0

32 files changed

+446
-822
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

justfile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,3 @@ verify-release: tmp
105105
--dir tmp \
106106
$VERSION
107107
cargo run verify tmp --key 3c977ea3a31cd37f0b540f02f33eab158f2ed7449f42b05613c921181aa95b79
108-
109-
render: tmp
110-
#!/usr/bin/env bash
111-
set -euxo pipefail
112-
VERSION=`bin/version`
113-
gh release download \
114-
--repo casey/filepack \
115-
--pattern '*' \
116-
--dir tmp \
117-
$VERSION
118-
rm tmp/filepack.json
119-
cargo run create tmp --sign --metadata metadata.yaml
120-
cargo run render tmp > tmp/index.html
121-
open tmp/index.html

src/archive.rs

Lines changed: 0 additions & 121 deletions
This file was deleted.

src/archive_error.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/error.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ use super::*;
33
#[derive(Debug, Snafu)]
44
#[snafu(context(suffix(false)), visibility(pub(crate)))]
55
pub(crate) enum Error {
6-
#[snafu(display("failed to load archive at `{path}`"))]
7-
ArchiveLoad {
8-
path: DisplayPath,
9-
source: ArchiveError,
10-
},
116
#[snafu(display("failed to get current directory"))]
127
CurrentDir { source: io::Error },
138
#[snafu(display("failed to get local data directory"))]
@@ -56,13 +51,6 @@ pub(crate) enum Error {
5651
},
5752
#[snafu(display("fingerprint mismatch"))]
5853
FingerprintMismatch { backtrace: Option<Backtrace> },
59-
#[snafu(display("file `{path}` hash {actual} does not match manifest hash {expected}"))]
60-
HashMismatch {
61-
actual: Hash,
62-
backtrace: Option<Backtrace>,
63-
expected: Hash,
64-
path: DisplayPath,
65-
},
6654
#[snafu(display("public key `{public_key}` doesn't match private key `{private_key}`"))]
6755
KeyMismatch {
6856
backtrace: Option<Backtrace>,
@@ -174,13 +162,6 @@ pub(crate) enum Error {
174162
backtrace: Option<Backtrace>,
175163
key: PublicKey,
176164
},
177-
#[snafu(display("file `{path}` size {actual} does not match manifest size {expected}"))]
178-
SizeMismatch {
179-
actual: u64,
180-
backtrace: Option<Backtrace>,
181-
expected: u64,
182-
path: DisplayPath,
183-
},
184165
#[snafu(display("I/O error reading standard input"))]
185166
StandardInputIo {
186167
backtrace: Option<Backtrace>,

src/hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl Hash {
1010
self.0.as_bytes()
1111
}
1212

13+
#[cfg(test)]
1314
pub(crate) fn bytes(input: &[u8]) -> Self {
1415
Self(blake3::hash(input))
1516
}

src/into_u64.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main.rs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
use {
22
self::{
3-
archive::Archive, archive_error::ArchiveError, arguments::Arguments, bytes::Bytes,
4-
display_path::DisplayPath, display_secret::DisplaySecret, entry::Entry, error::Error,
5-
hash::Hash, into_u64::IntoU64, lint::Lint, lint_group::LintGroup, list::List,
3+
arguments::Arguments, bytes::Bytes, display_path::DisplayPath, display_secret::DisplaySecret,
4+
entry::Entry, error::Error, hash::Hash, lint::Lint, lint_group::LintGroup, list::List,
65
manifest::Manifest, metadata::Metadata, options::Options, owo_colorize_ext::OwoColorizeExt,
7-
page::Page, private_key::PrivateKey, public_key::PublicKey, relative_path::RelativePath,
6+
package::Package, private_key::PrivateKey, public_key::PublicKey, relative_path::RelativePath,
87
signature::Signature, signature_error::SignatureError, style::Style, subcommand::Subcommand,
98
template::Template, utf8_path_ext::Utf8PathExt,
109
},
1110
blake3::Hasher,
1211
boilerplate::Boilerplate,
1312
camino::{Utf8Component, Utf8Path, Utf8PathBuf},
1413
clap::{Parser, ValueEnum},
15-
html_escaper::Escape,
14+
html_escaper::{Escape, Trusted},
1615
indicatif::{ProgressBar, ProgressStyle},
1716
lexiclean::Lexiclean,
1817
owo_colors::Styled,
1918
serde::{Deserialize, Deserializer, Serialize, Serializer},
2019
serde_with::{DeserializeFromStr, SerializeDisplay},
21-
snafu::{ensure, ErrorCompat, IntoError, OptionExt, ResultExt, Snafu},
20+
snafu::{ensure, ErrorCompat, OptionExt, ResultExt, Snafu},
2221
std::{
2322
array::TryFromSliceError,
2423
backtrace::{Backtrace, BacktraceStatus},
2524
cmp::Ordering,
26-
collections::{BTreeMap, HashMap, HashSet},
25+
collections::{BTreeMap, HashMap},
2726
env,
2827
fmt::{self, Display, Formatter},
29-
fs::{self, File},
30-
io::{self, BufReader, BufWriter, IsTerminal, Read, Write},
28+
fs::File,
29+
io::{self, IsTerminal},
3130
path::{Path, PathBuf},
3231
process,
3332
str::{self, FromStr},
@@ -38,27 +37,42 @@ use {
3837
};
3938

4039
#[cfg(test)]
41-
use assert_fs::{
42-
fixture::{FileWriteBin, PathChild},
43-
TempDir,
40+
use {
41+
assert_fs::{
42+
fixture::{FileWriteStr, PathChild, PathCreateDir},
43+
TempDir,
44+
},
45+
std::ffi::OsString,
4446
};
4547

4648
#[cfg(test)]
47-
macro_rules! assert_matches {
48-
($expression:expr, $( $pattern:pat_param )|+ $( if $guard:expr )? $(,)?) => {
49-
match $expression {
50-
$( $pattern )|+ $( if $guard )? => {}
51-
left => panic!(
52-
"assertion failed: (left ~= right)\n left: `{:?}`\n right: `{}`",
53-
left,
54-
stringify!($($pattern)|+ $(if $guard)?)
55-
),
49+
macro_rules! command {
50+
( $($argument:expr),* $(,)?) => {
51+
{
52+
#![allow(clippy::vec_init_then_push)]
53+
54+
let mut arguments = Vec::<OsString>::new();
55+
56+
arguments.push("filepack".into());
57+
58+
arguments.push("--quiet".into());
59+
60+
$(
61+
arguments.push($argument.into());
62+
)*
63+
64+
let arguments = match Arguments::try_parse_from(arguments) {
65+
Ok(arguments) => arguments,
66+
Err(error) => {
67+
panic!("{error}");
68+
}
69+
};
70+
71+
arguments.run().unwrap();
5672
}
57-
}
73+
};
5874
}
5975

60-
mod archive;
61-
mod archive_error;
6276
mod arguments;
6377
mod bytes;
6478
mod display_path;
@@ -67,15 +81,14 @@ mod entry;
6781
mod error;
6882
mod filesystem;
6983
mod hash;
70-
mod into_u64;
7184
mod lint;
7285
mod lint_group;
7386
mod list;
7487
mod manifest;
7588
mod metadata;
7689
mod options;
7790
mod owo_colorize_ext;
78-
mod page;
91+
mod package;
7992
mod private_key;
8093
mod progress_bar;
8194
mod public_key;

src/manifest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
#[derive(Debug, Deserialize, PartialEq, Serialize)]
3+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
44
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
55
pub(crate) struct Manifest {
66
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
@@ -25,7 +25,7 @@ impl Manifest {
2525
hasher.finalize().into()
2626
}
2727

28-
pub(crate) fn load(path: Option<&Utf8Path>) -> Result<(Utf8PathBuf, String, Self)> {
28+
pub(crate) fn load(path: Option<&Utf8Path>) -> Result<(Utf8PathBuf, Self)> {
2929
let path = if let Some(path) = path {
3030
if filesystem::metadata(path)?.is_dir() {
3131
path.join(Manifest::FILENAME)
@@ -42,7 +42,7 @@ impl Manifest {
4242
let manifest =
4343
serde_json::from_str(&json).context(error::DeserializeManifest { path: &path })?;
4444

45-
Ok((path, json, manifest))
45+
Ok((path, manifest))
4646
}
4747

4848
pub(crate) fn store(&self, path: &Utf8Path) -> Result<()> {

src/metadata.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
#[derive(Debug, Deserialize, Serialize)]
3+
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
44
#[serde(rename_all = "kebab-case")]
55
pub(crate) struct Metadata {
66
pub(crate) title: String,
@@ -9,11 +9,6 @@ pub(crate) struct Metadata {
99
impl Metadata {
1010
pub(crate) const FILENAME: &'static str = "metadata.json";
1111

12-
pub(crate) fn load(path: &Utf8Path) -> Result<Self> {
13-
serde_json::from_str(&filesystem::read_to_string(path)?)
14-
.context(error::DeserializeMetadata { path })
15-
}
16-
1712
pub(crate) fn store(&self, path: &Utf8Path) -> Result<()> {
1813
filesystem::write(path, format!("{}\n", serde_json::to_string(self).unwrap()))
1914
}

0 commit comments

Comments
 (0)