diff --git a/src/commands/build/mod.rs b/src/commands/build/mod.rs index 249a63a..a6ec3f7 100644 --- a/src/commands/build/mod.rs +++ b/src/commands/build/mod.rs @@ -4,13 +4,12 @@ use clap::Parser; use std::env; use std::fs::{self, File, OpenOptions}; use std::io::{prelude::*, BufReader}; -use std::os::unix::prelude::PermissionsExt; use std::path::PathBuf; use std::process::Command; use std::thread; use std::{fs::create_dir_all, fs::remove_dir_all, path::Path}; -use crate::util::{get_config, Config, Print, DEV_DIR, PATHSEP, PROD_DIR, SEP}; +use crate::util::{get_config, set_permissions, Config, Print, DEV_DIR, PATHSEP, PROD_DIR, SEP}; use super::install::apply_changes; @@ -361,12 +360,7 @@ pub fn build_thread( )) .unwrap() .permissions(); - perms.set_mode(0o511); - - if perms.mode() != 0o511 { - Print::error("Unable to change file permissions."); - return Err(()); - } + set_permissions(&mut perms, 0o511); Print::info("Compiled successfully."); diff --git a/src/commands/dev/mod.rs b/src/commands/dev/mod.rs index b332eb3..47da3a4 100644 --- a/src/commands/dev/mod.rs +++ b/src/commands/dev/mod.rs @@ -5,13 +5,13 @@ use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use regex::Regex; use std::fs::{self, create_dir_all, remove_dir_all, File}; use std::io::Write; -use std::os::unix::prelude::PermissionsExt; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; use std::sync::mpsc::channel; use std::time::Instant; use std::{env, thread, time}; +use crate::util::set_permissions; use crate::util::{blame::BLAME, get_config, Config, Print, DEV_DIR, SEP}; use super::build::seed_cmd; @@ -117,13 +117,7 @@ fn dev_compile(config: Config) -> Result<(), ()> { )) .unwrap() .permissions(); - perms.set_mode(0o511); - - if perms.mode() != 0o511 { - Print::error("Unable to change file permissions."); - return Err(()); - } - + set_permissions(&mut perms, 0o511); Ok(()) } diff --git a/src/util.rs b/src/util.rs index 0f32702..05acedf 100644 --- a/src/util.rs +++ b/src/util.rs @@ -4,6 +4,7 @@ use console::style; use dirs; use std::collections::hash_map::DefaultHasher; use std::env; +use std::fs::Permissions; use std::hash::{Hash, Hasher}; use serde_derive::{Deserialize, Serialize}; @@ -208,3 +209,23 @@ impl Print { ) } } + +#[cfg(unix)] +pub fn set_permissions(metadata_permissions: &mut Permissions, mode: u32) -> Result<(), ()> { + use std::os::unix::prelude::PermissionsExt; + + metadata_permissions.set_mode(0o511); + + if metadata_permissions.mode() != 0o511 { + Print::error("Unable to change file permissions."); + return Err(()); + } + + Ok(()) +} + +#[cfg(not(unix))] +#[allow(unused)] +pub fn set_permissions(metadata_permissions: &mut Permissions, mode: u32) -> Result<(), ()> { + Ok(()) +}