1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extern crate libc;

pub mod config;
pub mod error;
pub mod installer;
pub mod makefile;
pub mod validator;

use crate::config::{SKIN_CONFIG_DIRECTORY, SKIN_SKINNERS_DIRECTORY, SKIN_TEMP_DIRECTORY};
use std::fs;

pub fn setup_config_dir(custom_path: Option<&str>) -> Result<(), std::io::Error> {
	for s_path in [
		SKIN_CONFIG_DIRECTORY,
		SKIN_SKINNERS_DIRECTORY,
		SKIN_TEMP_DIRECTORY,
	] {
		let path = custom_path.unwrap_or(s_path);
		let expanded_path = shellexpand::tilde(path).into_owned();

		if fs::metadata(&expanded_path).is_err() {
			fs::create_dir_all(&expanded_path)?;
		}
	}

	Ok(())
}

pub fn as_root() -> bool {
	let uid = unsafe { libc::getuid() };
	uid == 0
}