diff options
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/minemod.rs | 12 | ||||
-rw-r--r-- | src/util.rs | 21 | ||||
-rw-r--r-- | src/world.rs | 3 |
7 files changed, 27 insertions, 20 deletions
@@ -265,12 +265,6 @@ dependencies = [ ] [[package]] -name = "fs_extra" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394" - -[[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -472,7 +466,6 @@ dependencies = [ "anyhow", "clap", "dirs", - "fs_extra", "itertools", "log", "once_cell", @@ -10,7 +10,6 @@ edition = "2018" anyhow = "1.0.45" clap = "2.33.3" dirs = "4.0.0" -fs_extra = "1.2.0" itertools = "0.10.1" log = "0.4.14" once_cell = "1.8.0" diff --git a/src/error.rs b/src/error.rs index d60fabd..08539c0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,8 +14,6 @@ pub enum Error { InvalidScrape, #[error("'{0}' is not a valid mod directory")] InvalidModDir(PathBuf), - #[error("filesystem error")] - FsExtraError(#[from] fs_extra::error::Error), #[error("ZIP error")] ZipError(#[from] zip::result::ZipError), #[error("the downloaded file was empty")] @@ -16,6 +16,7 @@ pub mod error; pub mod game; pub mod kvstore; pub mod minemod; +mod util; pub mod world; pub use baas::{Baas, Snapshot}; diff --git a/src/minemod.rs b/src/minemod.rs index d90605c..9162907 100644 --- a/src/minemod.rs +++ b/src/minemod.rs @@ -5,11 +5,9 @@ use std::{ path::{Path, PathBuf}, }; -use fs_extra::dir::{self, CopyOptions}; - use super::{ error::{Error, Result}, - kvstore, scan, + kvstore, scan, util, }; /// The type of the ID that is used to identify Minetest mods. @@ -68,11 +66,9 @@ impl MineMod { /// /// Returns a new [`MineMod`] object pointing to the copy. pub fn copy_to<P: AsRef<Path>>(&self, path: P) -> Result<MineMod> { - let mut options = CopyOptions::new(); - options.content_only = true; let path = path.as_ref().join(self.mod_id()?); fs::create_dir_all(&path)?; - dir::copy(&self.path, &path, &options)?; + util::copy_recursive(&self.path, &path)?; MineMod::open(&path) } } @@ -134,11 +130,9 @@ impl Modpack { /// /// Returns a new [`Modpack`] object pointing to the copy. pub fn copy_to<P: AsRef<Path>>(&self, path: P) -> Result<Modpack> { - let mut options = CopyOptions::new(); - options.content_only = true; let path = path.as_ref().join(self.name()?); fs::create_dir_all(&path)?; - dir::copy(&self.path, &path, &options)?; + util::copy_recursive(&self.path, &path)?; Modpack::open(&path) } } diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..24b8701 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,21 @@ +use std::{fs, io, path::Path}; + +/// Recursively copy the *contents* of the given directory to the given path. +pub fn copy_recursive<S: AsRef<Path>, D: AsRef<Path>>(source: S, destination: D) -> io::Result<()> { + copy_inner(source.as_ref(), destination.as_ref()) +} + +fn copy_inner(source: &Path, destination: &Path) -> io::Result<()> { + for item in fs::read_dir(source)? { + let item = item?; + let metadata = item.metadata()?; + let item_destination = destination.join(item.file_name()); + if metadata.is_file() { + fs::copy(&item.path(), &item_destination)?; + } else if metadata.is_dir() { + fs::create_dir(&item_destination)?; + copy_inner(&item.path(), &item_destination)?; + } + } + Ok(()) +} diff --git a/src/world.rs b/src/world.rs index 79ba3f9..31ddbd4 100644 --- a/src/world.rs +++ b/src/world.rs @@ -37,7 +37,8 @@ impl World { /// Returns the name of the world. pub fn world_name(&self) -> Result<String> { - let fallback = self.path + let fallback = self + .path .file_name() .map(|s| s.to_str().expect("Non-UTF8 directory encountered")); |