Skip to content

Commit 21ae761

Browse files
authored
Adapt to new jbk utf8 locator (#104)
2 parents 783bffa + b765780 commit 21ae761

File tree

8 files changed

+45
-41
lines changed

8 files changed

+45
-41
lines changed

Cargo.lock

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

arx/src/create.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use log::{debug, info};
44
use std::cell::Cell;
55
use std::fs::File;
66
use std::io::{BufRead, BufReader};
7-
use std::path::{Path, PathBuf};
7+
use std::path::{absolute, Path, PathBuf};
88
use std::rc::Rc;
99
use std::sync::Arc;
1010

@@ -86,7 +86,7 @@ pub struct Options {
8686
required_unless_present("list_compressions"),
8787
value_hint=ValueHint::FilePath,
8888
)]
89-
outfile: Option<PathBuf>,
89+
outfile: Option<jbk::Utf8PathBuf>,
9090

9191
/// Remove STRIP_PREFIX from the entries' name added to the archive.
9292
#[arg(long, required = false, value_hint=ValueHint::DirPath, help_heading="Input options")]
@@ -192,6 +192,7 @@ fn check_input_paths_exist(file_list: &[PathBuf]) -> Result<()> {
192192
}
193193

194194
fn check_output_path_writable(out_file: &Path, force: bool) -> Result<()> {
195+
let out_file = absolute(out_file)?;
195196
if !out_file.parent().unwrap().is_dir() {
196197
Err(anyhow!(
197198
"Directory {} doesn't exist",
@@ -282,8 +283,7 @@ pub fn create(options: Options) -> Result<()> {
282283
let out_file = options.outfile.as_ref().expect(
283284
"Clap unsure it is Some, except if we have list_compressions, and so we return early",
284285
);
285-
let out_file = std::env::current_dir()?.join(out_file);
286-
check_output_path_writable(&out_file, options.force)?;
286+
check_output_path_writable(out_file.as_std_path(), options.force)?;
287287

288288
info!("Creating archive {:?}", out_file);
289289
let file_list = options
@@ -302,7 +302,7 @@ pub fn create(options: Options) -> Result<()> {
302302
};
303303
let cache_progress = Rc::new(CachedSize::new());
304304
let mut creator = arx::create::SimpleCreator::new(
305-
&out_file,
305+
out_file,
306306
match options.concat_mode {
307307
None => jbk::creator::ConcatMode::OneFile,
308308
Some(e) => e.into(),
@@ -341,7 +341,7 @@ pub fn create(options: Options) -> Result<()> {
341341
}
342342
};
343343

344-
let ret = creator.finalize(&out_file);
344+
let ret = creator.finalize();
345345
debug!("Saved place is {}", cache_progress.0.get());
346346
Ok(ret?)
347347
}

arx/src/dump.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ fn dump_entry(
4444
MayMissPack::MISSING(pack_info) => {
4545
eprintln!(
4646
"Missing pack {}. Declared location is {}",
47-
pack_info.uuid,
48-
String::from_utf8_lossy(&pack_info.pack_location)
47+
pack_info.uuid, pack_info.pack_location
4948
);
5049
}
5150
}

libarx/src/create/creator.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::path::Path;
21
use std::rc::Rc;
32
use std::sync::Arc;
43

@@ -12,8 +11,8 @@ pub struct SimpleCreator {
1211
}
1312

1413
impl SimpleCreator {
15-
pub fn new<P: AsRef<Path>>(
16-
outfile: P,
14+
pub fn new(
15+
outfile: impl AsRef<jbk::Utf8Path>,
1716
concat_mode: ConcatMode,
1817
progress: Arc<dyn jbk::creator::Progress>,
1918
cache_progress: Rc<dyn jbk::creator::CacheProgress>,
@@ -37,12 +36,11 @@ impl SimpleCreator {
3736
})
3837
}
3938

40-
pub fn finalize(self, outfile: &Path) -> Void {
41-
Ok(self.cached_content_creator.into_inner().finalize(
42-
outfile,
43-
self.entry_store_creator,
44-
vec![],
45-
)?)
39+
pub fn finalize(self) -> Void {
40+
Ok(self
41+
.cached_content_creator
42+
.into_inner()
43+
.finalize(self.entry_store_creator, vec![])?)
4644
}
4745

4846
pub fn adder(&mut self) -> &mut impl ContentAdder {

libarx/src/tools.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ where
310310
"Missing pack {} for {}. Declared location is {}",
311311
pack_info.uuid,
312312
abs_path.display(),
313-
String::from_utf8_lossy(&pack_info.pack_location)
313+
pack_info.pack_location
314314
);
315315
}
316316
}

python/src/creator.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ use pyo3::prelude::*;
1616
pub struct Creator {
1717
started: bool,
1818
creator: Option<SimpleCreator>,
19-
outfile: PathBuf,
2019
}
2120

2221
#[pymethods]
2322
impl Creator {
2423
#[new]
25-
fn new(outfile: PathBuf) -> PyResult<Self> {
24+
fn new(outfile: String) -> PyResult<Self> {
2625
Ok(Self {
2726
started: false,
2827
creator: Some(
@@ -35,7 +34,6 @@ impl Creator {
3534
)
3635
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?,
3736
),
38-
outfile,
3937
})
4038
}
4139

@@ -63,7 +61,7 @@ impl Creator {
6361
match slf.creator.take() {
6462
None => Err(PyRuntimeError::new_err("Creator already finalized")),
6563
Some(creator) => creator
66-
.finalize(&slf.outfile)
64+
.finalize()
6765
.map_err(|e| PyRuntimeError::new_err(e.to_string())),
6866
}
6967
}

tar2arx/src/main.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clap::{CommandFactory, Parser, ValueHint};
44
use anyhow::{anyhow, Result};
55
use jbk::creator::ContentAdder;
66
use std::io::Read;
7-
use std::path::{Path, PathBuf};
87
use std::rc::Rc;
98
use std::sync::Arc;
109

@@ -36,7 +35,7 @@ struct Cli {
3635
value_parser,
3736
value_hint=ValueHint::FilePath
3837
)]
39-
outfile: Option<PathBuf>,
38+
outfile: Option<jbk::Utf8PathBuf>,
4039

4140
#[command(flatten)]
4241
concat_mode: Option<jbk::cmd_utils::ConcatMode>,
@@ -239,9 +238,9 @@ impl arx::create::EntryTrait for TarEntry {
239238
}
240239

241240
impl<R: Read> Converter<R> {
242-
pub fn new<P: AsRef<Path>>(
241+
pub fn new(
243242
archive: tar::Archive<R>,
244-
outfile: P,
243+
outfile: impl AsRef<jbk::Utf8Path>,
245244
concat_mode: jbk::creator::ConcatMode,
246245
compression: jbk::creator::Compression,
247246
progress_bar: indicatif::ProgressBar,
@@ -261,19 +260,19 @@ impl<R: Read> Converter<R> {
261260
})
262261
}
263262

264-
fn finalize(self, outfile: &Path) -> Result<(), arx::CreatorError> {
265-
self.arx_creator.finalize(outfile)
263+
fn finalize(self) -> Result<(), arx::CreatorError> {
264+
self.arx_creator.finalize()
266265
}
267266

268-
pub fn run(mut self, outfile: &Path) -> Result<(), arx::CreatorError> {
267+
pub fn run(mut self) -> Result<(), arx::CreatorError> {
269268
let iter = self.archive.entries()?;
270269
for entry in iter {
271270
let entry = entry?;
272271
if let Some(entry) = TarEntry::new(entry, self.arx_creator.adder())? {
273272
self.arx_creator.add_entry(&entry)?;
274273
}
275274
}
276-
self.finalize(outfile)
275+
self.finalize()
277276
}
278277
}
279278

@@ -312,9 +311,9 @@ fn main() -> Result<()> {
312311
}
313312

314313
let outfile = args.outfile.unwrap_or_else(|| {
315-
let p = Path::new(args.tar_file.as_ref().unwrap());
314+
let p = jbk::Utf8Path::new(args.tar_file.as_ref().unwrap());
316315
let p = if p.starts_with("https://") || p.starts_with("http://") {
317-
Path::new(p.file_name().unwrap())
316+
jbk::Utf8Path::new(p.file_name().unwrap())
318317
.with_extension("")
319318
.with_extension("arx")
320319
} else {
@@ -362,5 +361,5 @@ fn main() -> Result<()> {
362361
args.compression,
363362
progress_bar,
364363
)?;
365-
Ok(converter.run(&outfile)?)
364+
Ok(converter.run()?)
366365
}

zip2arx/src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Cli {
4141
),
4242
value_hint=ValueHint::FilePath
4343
)]
44-
outfile: Option<PathBuf>,
44+
outfile: Option<jbk::Utf8PathBuf>,
4545

4646
#[command(flatten)]
4747
concat_mode: Option<jbk::cmd_utils::ConcatMode>,
@@ -226,10 +226,10 @@ impl arx::create::EntryTrait for ZipEntry {
226226
}
227227

228228
impl<R: Read + Seek> Converter<R> {
229-
pub fn new<P: AsRef<Path>>(
229+
pub fn new(
230230
archive: zip::ZipArchive<R>,
231231
archive_path: PathBuf,
232-
outfile: P,
232+
outfile: impl AsRef<jbk::Utf8Path>,
233233
concat_mode: jbk::creator::ConcatMode,
234234
) -> Result<Self, arx::CreatorError> {
235235
let progress = Arc::new(ProgressBar::new(&archive));
@@ -249,18 +249,18 @@ impl<R: Read + Seek> Converter<R> {
249249
})
250250
}
251251

252-
fn finalize(self, outfile: &Path) -> Result<(), arx::CreatorError> {
253-
self.arx_creator.finalize(outfile)
252+
fn finalize(self) -> Result<(), arx::CreatorError> {
253+
self.arx_creator.finalize()
254254
}
255255

256-
pub fn run(mut self, outfile: &Path) -> Result<(), arx::CreatorError> {
256+
pub fn run(mut self) -> Result<(), arx::CreatorError> {
257257
for idx in 0..self.archive.len() {
258258
self.progress.entries.inc(1);
259259
let entry = self.archive.by_index(idx).unwrap();
260260
let entry = ZipEntry::new(entry, self.arx_creator.adder(), &self.archive_path)?;
261261
self.arx_creator.add_entry(&entry)?;
262262
}
263-
self.finalize(outfile)
263+
self.finalize()
264264
}
265265
}
266266

@@ -302,5 +302,5 @@ fn main() -> Result<(), arx::CreatorError> {
302302
Some(e) => e.into(),
303303
},
304304
)?;
305-
converter.run(args.outfile.as_ref().unwrap())
305+
converter.run()
306306
}

0 commit comments

Comments
 (0)