Skip to content

Commit

Permalink
Adapt to new jbk utf8 locator
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Feb 1, 2025
1 parent b9688fe commit 98cb27c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions libwaj/src/create/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct FsCreator {
}

impl FsCreator {
pub fn new<P: AsRef<Path>>(
outfile: P,
pub fn new(
outfile: impl AsRef<jbk::Utf8Path>,
namer: Box<dyn Namer>,
concat_mode: ConcatMode,
progress: Arc<dyn jbk::creator::Progress>,
Expand All @@ -58,12 +58,11 @@ impl FsCreator {
})
}

pub fn finalize(self, outfile: &Path) -> Void {
Ok(self.cached_content_creator.into_inner().finalize(
outfile,
self.entry_store_creator,
vec![],
)?)
pub fn finalize(self) -> Void {
Ok(self
.cached_content_creator
.into_inner()
.finalize(self.entry_store_creator, vec![])?)
}

pub fn add_from_path(&mut self, path: &Path) -> Void {
Expand Down
8 changes: 4 additions & 4 deletions libwaj/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ impl RequestHandler {
let (msg, mimetype, status_code) = match mimetype {
"text/html" | "text/css" | "application/javascript" => {
let msg = format!(
"<h1>Missing contentPack {}.</h1><p>Declared location is <pre>{}</pre></p><p>Found the pack and you are good !!</p>",
pack_info.uuid,
String::from_utf8_lossy(&pack_info.pack_location),
);
"<h1>Missing contentPack {}.</h1><p>Declared location is <pre>{}</pre></p><p>Found the pack and you are good !!</p>",
pack_info.uuid,
pack_info.pack_location,
);
(msg, "text/html", 503)
}
_ => {
Expand Down
12 changes: 6 additions & 6 deletions src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::{Parser, ValueHint};
use std::cell::Cell;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use std::path::{absolute, Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
use waj::create::StripPrefix;
Expand All @@ -21,7 +21,7 @@ pub struct Options {
required_unless_present("list_compressions"),
value_hint=ValueHint::FilePath,
)]
outfile: Option<PathBuf>,
outfile: Option<jbk::Utf8PathBuf>,

/// Remove STRIP_PREFIX from the entries' name added to the archive.
#[arg(long, required = false, value_hint=ValueHint::DirPath)]
Expand Down Expand Up @@ -71,6 +71,7 @@ pub struct Options {
}

fn check_output_path_writable(out_file: &Path, force: bool) -> Result<()> {
let out_file = absolute(out_file)?;
if !out_file.parent().unwrap().is_dir() {
Err(anyhow!(
"Directory {} doesn't exist",
Expand Down Expand Up @@ -166,8 +167,7 @@ pub fn create(options: Options) -> Result<()> {
let out_file = options.outfile.as_ref().expect(
"Clap unsure it is Some, except if we have list_compressions, and so we return early",
);
let out_file = std::env::current_dir()?.join(out_file);
check_output_path_writable(&out_file, options.force)?;
check_output_path_writable(out_file.as_std_path(), options.force)?;

let file_list = options
.file_list
Expand All @@ -184,7 +184,7 @@ pub fn create(options: Options) -> Result<()> {

let namer = Box::new(StripPrefix::new(strip_prefix));
let mut creator = waj::create::FsCreator::new(
&out_file,
out_file,
namer,
match options.concat_mode {
None => jbk::creator::ConcatMode::OneFile,
Expand Down Expand Up @@ -224,6 +224,6 @@ pub fn create(options: Options) -> Result<()> {
creator.add_redirect("", &main_page)?;
}

let ret = creator.finalize(&out_file);
let ret = creator.finalize();
Ok(ret?)
}

0 comments on commit 98cb27c

Please sign in to comment.