Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.");

Expand Down
10 changes: 2 additions & 8 deletions src/commands/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}

Expand Down
21 changes: 21 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(())
}