aboutsummaryrefslogtreecommitdiff
path: root/src/util.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-11-09 12:46:43 +0100
committerDaniel Schadt <kingdread@gmx.de>2021-11-09 12:50:33 +0100
commitd21c5dc9c53b02620fce916ffc1a2695e9d3f698 (patch)
treefb17ba6ee4e0a1ed532ab6e570418abff5264616 /src/util.rs
parent919796ec954414ae16f113896bdf212381c96437 (diff)
downloadmodderbaas-d21c5dc9c53b02620fce916ffc1a2695e9d3f698.tar.gz
modderbaas-d21c5dc9c53b02620fce916ffc1a2695e9d3f698.tar.bz2
modderbaas-d21c5dc9c53b02620fce916ffc1a2695e9d3f698.zip
Separate the binary and library
This uses the workspace feature of cargo, with the benefit that 1) We can more cleanly group the binary (user facing) code from the library 2) We can have dependencies that apply to the binary only The first point could've been achieved without workspaces (Cargo supports both binaries and libraries in a crate), but the second point is what really makes this approach a lot better.
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/util.rs b/src/util.rs
deleted file mode 100644
index ea401ba..0000000
--- a/src/util.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-//! Utility functions.
-use std::{fs, io, path::Path};
-
-#[cfg(unix)]
-use nix::unistd::{self, Gid, Uid};
-
-use super::error::Result;
-
-#[cfg(not(unix))]
-pub mod nix {
- //! Stub mod on non-unix systems.
- pub mod unistd {
- pub enum Uid {}
- pub enum Gid {}
- }
-}
-
-/// 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(())
-}
-
-/// Recursively change the owner of the given path to the given ones.
-///
-/// Note that this function only works on Unix systems. **It will panic on other systems!**
-pub fn chown_recursive<P: AsRef<Path>>(path: P, uid: Option<Uid>, gid: Option<Gid>) -> Result<()> {
- chown_inner(path.as_ref(), uid, gid)
-}
-
-#[cfg(unix)]
-fn chown_inner(path: &Path, uid: Option<Uid>, gid: Option<Gid>) -> Result<()> {
- unistd::chown(path, uid, gid)?;
-
- let metadata = fs::metadata(path)?;
- if metadata.is_dir() {
- for item in fs::read_dir(path)? {
- let item = item?;
- chown_inner(&item.path(), uid, gid)?;
- }
- }
- Ok(())
-}
-
-#[cfg(not(unix))]
-fn chown_inner(_: &Path, _: Option<Uid>, _: Option<Gid>) -> Result<()> {
- panic!("chown() is not available on non-Unix systems!");
-}