Skip to content

Commit

Permalink
Directly use jubako with name "jbk" instead of rename it in all sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Feb 5, 2024
1 parent 4fad662 commit 51c2c9c
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/jubako/waj"
license = "MIT"

[workspace.dependencies]
jubako = { git = "https://github.com/jubako/jubako.git" }
jbk = { git = "https://github.com/jubako/jubako.git", package = "jubako" }

[package]
name = "waj"
Expand All @@ -26,5 +26,5 @@ license.workspace = true
[dependencies]
clap = { version = "4.0.32", features = ["derive"] }
libwaj = { path = "libwaj", version = "0.1.0" }
jubako.workspace = true
indicatif = "0.17.3"
jbk.workspace = true
2 changes: 1 addition & 1 deletion libwaj/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
jubako.workspace = true
jbk.workspace = true
percent-encoding = "2.2.0"
tiny_http = "0.12.0"
mime_guess = "2.0.4"
Expand Down
1 change: 0 additions & 1 deletion libwaj/src/common/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::entry::*;
use super::entry_type::EntryType;
use super::{AllProperties, Reader};
use jbk::reader::builder::PropertyBuilderTrait;
use jubako as jbk;

pub trait Builder {
type Entry;
Expand Down
2 changes: 0 additions & 2 deletions libwaj/src/common/entry_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use jubako as jbk;

#[repr(u8)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub enum EntryType {
Expand Down
1 change: 0 additions & 1 deletion libwaj/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub use entry::{Entry, EntryDef};
pub use entry_type::EntryType;
use jbk::reader::builder::{BuilderTrait, PropertyBuilderTrait};
use jbk::reader::Range;
use jubako as jbk;
pub use properties::{AllProperties, Property};

pub use jbk::SubReader as Reader;
Expand Down
2 changes: 0 additions & 2 deletions libwaj/src/common/properties.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use jubako as jbk;

#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub enum Property {
Path,
Expand Down
2 changes: 0 additions & 2 deletions libwaj/src/create/creator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use jubako as jbk;

use std::borrow::Cow;
use std::io::Seek;
use std::path::{Path, PathBuf};
Expand Down
49 changes: 24 additions & 25 deletions libwaj/src/create/entry.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::common::*;
use jubako::*;

pub struct Path1 {
value_id: creator::ValueHandle,
value_id: jbk::creator::ValueHandle,
prefix: u8,
size: u16,
}
static_assertions::assert_eq_size!(Path1, [u8; 24]);

impl Path1 {
pub fn new(mut path: Vec<u8>, value_store: &creator::StoreHandle) -> Self {
pub fn new(mut path: Vec<u8>, value_store: &jbk::creator::StoreHandle) -> Self {
// println!("Add path {path:?}");
let size = path.len() as u16;
let prefix = if size == 0 { 0 } else { path.remove(0) };
Expand All @@ -23,18 +22,18 @@ impl Path1 {
}

pub struct Content {
mimetype: creator::ValueHandle,
content_id: ContentIdx,
pack_id: PackId,
mimetype: jbk::creator::ValueHandle,
content_id: jbk::ContentIdx,
pack_id: jbk::PackId,
}
static_assertions::assert_eq_size!(Content, [u8; 24]);

pub struct Entry {
idx: Vow<EntryIdx>,
idx: jbk::Vow<jbk::EntryIdx>,
// The three path_* are technically a Path1.
// But extract the three fields from the Path1 allow compiler to
// reorganise the fields and reduce the structure size.
path_value_id: creator::ValueHandle,
path_value_id: jbk::creator::ValueHandle,
path_prefix: u8,
path_size: u16,

Expand All @@ -50,11 +49,11 @@ static_assertions::assert_eq_size!(Entry, [u8; 64]);
impl Entry {
pub fn new_content(
path: Path1,
mimetype: creator::ValueHandle,
content: ContentAddress,
mimetype: jbk::creator::ValueHandle,
content: jbk::ContentAddress,
) -> Self {
Self {
idx: Vow::new(0.into()),
idx: jbk::Vow::new(0.into()),
path_value_id: path.value_id,
path_prefix: path.prefix,
path_size: path.size,
Expand All @@ -68,7 +67,7 @@ impl Entry {

pub fn new_redirect(path: Path1, target: Path1) -> Self {
Self {
idx: Vow::new(0.into()),
idx: jbk::Vow::new(0.into()),
path_value_id: path.value_id,
path_prefix: path.prefix,
path_size: path.size,
Expand All @@ -78,46 +77,46 @@ impl Entry {
}
}

impl jubako::creator::EntryTrait<Property, EntryType> for Entry {
fn variant_name(&self) -> Option<jubako::MayRef<EntryType>> {
Some(jubako::MayRef::Owned(match self.kind {
impl jbk::creator::EntryTrait<Property, EntryType> for Entry {
fn variant_name(&self) -> Option<jbk::MayRef<EntryType>> {
Some(jbk::MayRef::Owned(match self.kind {
EntryKind::Content(_) => EntryType::Content,
EntryKind::Redirect(_) => EntryType::Redirect,
}))
}

fn value_count(&self) -> PropertyCount {
fn value_count(&self) -> jbk::PropertyCount {
match self.kind {
EntryKind::Content(_) => 3.into(),
EntryKind::Redirect(_) => 2.into(),
}
}

fn set_idx(&mut self, idx: EntryIdx) {
fn set_idx(&mut self, idx: jbk::EntryIdx) {
self.idx.fulfil(idx)
}

fn get_idx(&self) -> Bound<EntryIdx> {
fn get_idx(&self) -> jbk::Bound<jbk::EntryIdx> {
self.idx.bind()
}

fn value(&self, name: &Property) -> jubako::MayRef<creator::Value> {
jubako::MayRef::Owned(match name {
Property::Path => creator::Value::Array1(Box::new(creator::ArrayS::<1> {
fn value(&self, name: &Property) -> jbk::MayRef<jbk::creator::Value> {
jbk::MayRef::Owned(match name {
Property::Path => jbk::creator::Value::Array1(Box::new(jbk::creator::ArrayS::<1> {
data: [self.path_prefix],
value_id: self.path_value_id.clone_get(),
size: self.path_size as usize,
})),
Property::Mimetype => {
if let EntryKind::Content(content) = &self.kind {
creator::Value::IndirectArray(Box::new(content.mimetype.clone_get()))
jbk::creator::Value::IndirectArray(Box::new(content.mimetype.clone_get()))
} else {
unreachable!()
}
}
Property::Content => {
if let EntryKind::Content(content) = &self.kind {
creator::Value::Content(ContentAddress::new(
jbk::creator::Value::Content(jbk::ContentAddress::new(
content.pack_id,
content.content_id,
))
Expand All @@ -127,7 +126,7 @@ impl jubako::creator::EntryTrait<Property, EntryType> for Entry {
}
Property::Target => {
if let EntryKind::Redirect(target) = &self.kind {
creator::Value::Array1(Box::new(creator::ArrayS::<1> {
jbk::creator::Value::Array1(Box::new(jbk::creator::ArrayS::<1> {
data: [target.prefix],
value_id: target.value_id.clone_get(),
size: target.size as usize,
Expand All @@ -140,7 +139,7 @@ impl jubako::creator::EntryTrait<Property, EntryType> for Entry {
}
}

impl jubako::creator::FullEntryTrait<Property, EntryType> for Entry {
impl jbk::creator::FullEntryTrait<Property, EntryType> for Entry {
fn compare<'i, I>(&self, _sort_keys: &'i I, other: &Self) -> std::cmp::Ordering
where
I: IntoIterator<Item = &'i Property> + Copy,
Expand Down
5 changes: 1 addition & 4 deletions libwaj/src/create/entry_store_creator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use jubako as jbk;

use super::entry::{Entry, Path1};
use crate::common::{EntryType, Property};
use jbk::creator::schema;
Expand Down Expand Up @@ -64,7 +62,7 @@ impl EntryStoreCreator {
jbk::PropertyIdx::from(0),
entry_store_id,
jbk::EntryCount::from(entry_count as u32),
jubako::EntryIdx::from(0).into(),
jbk::EntryIdx::from(0).into(),
);
Ok(())
}
Expand Down Expand Up @@ -103,7 +101,6 @@ impl EntryStoreCreator {
mod tests {
use super::super::*;
use super::*;
use jubako as jbk;
use mime_guess::mime;

#[test]
Expand Down
2 changes: 0 additions & 2 deletions libwaj/src/create/fs_adder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use jubako as jbk;

use crate::create::{EntryKind, EntryStoreCreator, EntryTrait, Void};
use jbk::creator::InputReader;
use mime_guess::mime;
Expand Down
6 changes: 3 additions & 3 deletions libwaj/src/create/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ pub enum ConcatMode {
}

pub enum EntryKind {
Content(jubako::ContentAddress, mime_guess::Mime),
Content(jbk::ContentAddress, mime_guess::Mime),
Redirect(String),
}

pub trait EntryTrait {
/// The kind of the entry
fn kind(&self) -> jubako::Result<Option<EntryKind>>;
fn kind(&self) -> jbk::Result<Option<EntryKind>>;

/// Under which name the entry will be stored
fn name(&self) -> Cow<str>;
}

pub type Void = jubako::Result<()>;
pub type Void = jbk::Result<()>;
1 change: 0 additions & 1 deletion libwaj/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::common::{AllProperties, Builder, Reader};
use jbk::reader::builder::PropertyBuilderTrait;
use jubako as jbk;

pub struct CommonPart {
idx: jbk::EntryIdx,
Expand Down
3 changes: 1 addition & 2 deletions libwaj/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::common::{AllProperties, Builder, Entry, Reader};
use crate::Waj;
use ascii::IntoAsciiString;
use jbk::reader::builder::PropertyBuilderTrait;
use jubako as jbk;
use log::{error, info, trace};
use percent_encoding::{percent_decode, percent_encode, CONTROLS};
use std::borrow::Cow;
Expand Down Expand Up @@ -212,7 +211,7 @@ impl Server {

let now = std::time::Instant::now();

trace!("[{request_id}] : {} {url}", request.method());
println!("[{request_id}] : {} {url}", request.method());

let etag_match =
if let Some(request_etag) = get_etag_from_headers(request.headers()) {
Expand Down
3 changes: 1 addition & 2 deletions libwaj/src/waj.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::common::{AllProperties, Builder, Comparator, Entry, FullBuilderTrait, RealBuilder};
use jbk::reader::builder::PropertyBuilderTrait;
use jubako as jbk;
use jubako::reader::Range;
use jbk::reader::Range;
use std::path::Path;

pub use jbk::SubReader as Reader;
Expand Down
1 change: 0 additions & 1 deletion libwaj/src/walk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::common::*;
use super::Waj;
use jbk::reader::Range;
use jubako as jbk;

pub trait Operator<Context, Builder: FullBuilderTrait> {
fn on_start(&self, context: &mut Context) -> jbk::Result<()>;
Expand Down
1 change: 0 additions & 1 deletion src/bin/auto_serve.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jubako as jbk;
use libwaj as waj;

use std::env;
Expand Down
1 change: 0 additions & 1 deletion src/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jubako as jbk;
use libwaj as waj;

use std::cell::Cell;
Expand Down
1 change: 0 additions & 1 deletion src/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jubako as jbk;
use libwaj as waj;

use clap::Args;
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jubako as jbk;
use libwaj as waj;

mod create;
Expand Down

0 comments on commit 51c2c9c

Please sign in to comment.