diff options
Diffstat (limited to 'src')
-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 |
5 files changed, 27 insertions, 12 deletions
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")); |