From 3d1f03e1a334e18946990c45dcdfd4081cd528af Mon Sep 17 00:00:00 2001 From: Aksiome <54895777+aksiome@users.noreply.github.com> Date: Fri, 12 Apr 2024 00:38:26 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=E2=AC=86=EF=B8=8F=20Fix=20a=20few?= =?UTF-8?q?=20bugs=20&=20bump=20dependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 221 +++++++++++++++++++++--------------- Cargo.toml | 8 +- src/config.rs | 10 ++ src/entries/datapack.rs | 2 +- src/entries/extra.rs | 1 + src/entries/file.rs | 2 +- src/entries/level.rs | 2 +- src/entries/region.rs | 2 +- src/entries/resourcepack.rs | 2 +- src/entries/scoreboard.rs | 2 +- src/storage/zip.rs | 4 + src/utils.rs | 32 +++++- 12 files changed, 182 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf03ea4..c8b6418 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.5.0" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ "anstyle", "anstyle-parse", @@ -57,12 +57,12 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "2.1.0" +version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -89,6 +89,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "bstr" version = "1.3.0" @@ -131,9 +137,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.2" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -141,9 +147,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.2" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -153,9 +159,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ "heck", "proc-macro2", @@ -165,9 +171,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "color_quant" @@ -209,16 +215,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -293,12 +289,22 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", +] + [[package]] name = "env_logger" -version = "0.10.0" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" dependencies = [ + "env_filter", "log", ] @@ -377,6 +383,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + [[package]] name = "globset" version = "0.4.10" @@ -398,18 +413,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "ignore" @@ -467,16 +473,16 @@ dependencies = [ [[package]] name = "inquire" -version = "0.6.0" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd079157ad94a32f7511b2e13037f3ae417ad80a6a9b0de29154d48b86f5d6c8" +checksum = "fe95f33091b9b7b517a5849bce4dce1b550b430fc20d58059fcaa319ed895d8b" dependencies = [ - "bitflags", + "bitflags 2.5.0", "console", "dyn-clone", - "lazy_static", + "fxhash", "newline-converter", - "thiserror", + "once_cell", "unicode-segmentation", "unicode-width", ] @@ -526,12 +532,9 @@ checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" [[package]] name = "log" -version = "0.4.17" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "mcwpack" @@ -584,9 +587,9 @@ dependencies = [ [[package]] name = "newline-converter" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f71d09d5c87634207f894c6b31b6a2b2c64ea3bdcf71bd5599fdbbe1600c00f" +checksum = "47b6b097ecb1cbfed438542d16e84fd7ad9b0c76c8a65b7f9039212a3d14dc7f" dependencies = [ "unicode-segmentation", ] @@ -632,16 +635,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.11" @@ -671,9 +664,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.17.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "path-absolutize" @@ -711,9 +704,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] @@ -729,9 +722,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -739,14 +732,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -755,7 +746,7 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -790,7 +781,7 @@ version = "0.36.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", "io-lifetimes", "libc", @@ -869,9 +860,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" @@ -908,26 +899,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "thiserror" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "thread_local" version = "1.1.7" @@ -1087,6 +1058,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + [[package]] name = "windows-targets" version = "0.42.1" @@ -1117,6 +1097,21 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" @@ -1129,6 +1124,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.42.1" @@ -1141,6 +1142,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.42.1" @@ -1153,6 +1160,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.42.1" @@ -1165,6 +1178,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.42.1" @@ -1177,6 +1196,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" @@ -1189,6 +1214,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.42.1" @@ -1201,6 +1232,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + [[package]] name = "winnow" version = "0.3.5" diff --git a/Cargo.toml b/Cargo.toml index 992f230..051b3db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,21 +5,21 @@ edition = "2021" [dependencies] anyhow = "1.0" -clap = { version = "4.4", features = ["derive", "cargo"] } +clap = { version = "4.5", features = ["derive", "cargo"] } console = "0.15" derive_more = "0.99" edit = "0.1" -env_logger = { version = "0.10", default-features = false } +env_logger = { version = "0.11", default-features = false } fastanvil = "0" fastnbt = "2" flate2 = "1.0" globset = "0.4" ignore = "0.4" indicatif = { version = "0.17", features = ["rayon"] } -inquire = { version = "0.6", features = ["console"], default-features = false } +inquire = { version = "0.7", features = ["console"], default-features = false } log = "0.4" path-absolutize = "3.1" -rayon = "1.7" +rayon = "1.10" serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.9" zip = { version = "0.6", features = ["deflate", "time"], default-features = false } diff --git a/src/config.rs b/src/config.rs index a6d44f1..708e72f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf}; use globset::{Glob, GlobSet, GlobSetBuilder}; use ignore::overrides::{Override, OverrideBuilder}; +use path_absolutize::Absolutize; use serde::{Deserialize, Deserializer}; use crate::entries::ExtraEntry; @@ -85,6 +86,15 @@ where impl Config { pub fn load(path: &Path, noprompt: bool) -> Option { + let conf_path = path.absolutize().unwrap(); + let current_dir = std::env::current_dir().expect("could not get working dir"); + std::env::set_current_dir(path.parent()?).expect("could not set working dir"); + let config = Self::try_load(&conf_path, noprompt); + std::env::set_current_dir(current_dir).expect("could not set working dir"); + config + } + + fn try_load(path: &Path, noprompt: bool) -> Option { std::fs::read_to_string(path).map_or_else(|err| { log::error!("could not read the config file ({err})"); Self::try_edit(path, include_str!("../config.yaml"), noprompt) diff --git a/src/entries/datapack.rs b/src/entries/datapack.rs index 9f55bc6..4814ef2 100644 --- a/src/entries/datapack.rs +++ b/src/entries/datapack.rs @@ -1,4 +1,4 @@ -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use crate::utils; use super::*; diff --git a/src/entries/extra.rs b/src/entries/extra.rs index 6668032..d2a72df 100644 --- a/src/entries/extra.rs +++ b/src/entries/extra.rs @@ -5,6 +5,7 @@ use serde::Deserialize; use super::*; #[derive(Clone, Debug, Deserialize, From)] +#[serde(untagged)] pub enum ExtraEntry { Short(PathBuf), Full(PathBuf, PathBuf), diff --git a/src/entries/file.rs b/src/entries/file.rs index 8dd5d3b..893815a 100644 --- a/src/entries/file.rs +++ b/src/entries/file.rs @@ -1,4 +1,4 @@ -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use super::*; #[derive(Clone, Debug, Deref, From)] diff --git a/src/entries/level.rs b/src/entries/level.rs index 3e1a1fb..8abb75c 100644 --- a/src/entries/level.rs +++ b/src/entries/level.rs @@ -1,5 +1,5 @@ use crate::formats::{Level, NbtFormat}; -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use super::*; #[derive(Clone, Debug, Deref, From)] diff --git a/src/entries/region.rs b/src/entries/region.rs index d828987..015c263 100644 --- a/src/entries/region.rs +++ b/src/entries/region.rs @@ -1,5 +1,5 @@ use crate::formats::Region; -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use super::*; #[derive(Clone, Debug, Deref, From)] diff --git a/src/entries/resourcepack.rs b/src/entries/resourcepack.rs index a7b90f4..cb1f9eb 100644 --- a/src/entries/resourcepack.rs +++ b/src/entries/resourcepack.rs @@ -1,4 +1,4 @@ -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use crate::utils; use super::*; diff --git a/src/entries/scoreboard.rs b/src/entries/scoreboard.rs index a202e6e..1fb89cd 100644 --- a/src/entries/scoreboard.rs +++ b/src/entries/scoreboard.rs @@ -1,5 +1,5 @@ use crate::formats::{NbtFormat, Scoreboard}; -use crate::utils::PrefixPath; +use crate::utils::PathUtils; use super::*; #[derive(Clone, Debug, Deref, From)] diff --git a/src/storage/zip.rs b/src/storage/zip.rs index 69abef1..eb6c803 100644 --- a/src/storage/zip.rs +++ b/src/storage/zip.rs @@ -26,6 +26,10 @@ impl InMemoryStorage for ZipStorage>> { impl FilesystemStorage for ZipStorage { fn new(path: &Path) -> Self { + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent).unwrap(); + } + Self { path: Some(path.to_owned()), writer: Mutex::new(ZipWriter::new(File::create(path).unwrap())), diff --git a/src/utils.rs b/src/utils.rs index d8c71f8..717897f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::{Component, Path, PathBuf}; use std::str::FromStr; use std::time::Duration; @@ -9,13 +9,37 @@ use inquire::{Confirm, CustomUserError, Text}; use crate::storage::{InMemoryStorage, Storage, ZipStorage}; -pub trait PrefixPath { +pub trait PathUtils { fn prefix>(&self, prefix: Option

) -> PathBuf; + fn normalize(&self) -> PathBuf; } -impl PrefixPath for PathBuf { +impl PathUtils for PathBuf { fn prefix>(&self, prefix: Option

) -> PathBuf { - prefix.map_or_else(|| self.to_owned(), |p| p.as_ref().join(self)) + match prefix { + Some(p) => p.as_ref().join(self), + None => self.to_owned(), + }.normalize() + } + + fn normalize(&self) -> PathBuf { + let mut components = self.components().peekable(); + let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() { + components.next(); + PathBuf::from(c.as_os_str()) + } else { + PathBuf::new() + }; + for component in components { + match component { + Component::Prefix(..) => unreachable!(), + Component::RootDir => ret.push(component.as_os_str()), + Component::CurDir => {} + Component::ParentDir => {ret.pop();}, + Component::Normal(c) => ret.push(c), + } + } + ret } }