diff --git a/README.md b/README.md index ed93e148..f6625c15 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,19 @@ cargo install rrdb - 플랫폼별 처리 (Linux) +심볼릭 링크를 생성하고 초기화를 수행합니다. + ``` sudo ln -s /home/$USER/.cargo/bin/rrdb /usr/bin/rrdb +sudo rrdb init +``` + +- 플랫폼별 처리 (Windows) + +powershell을 관리자 권한으로 실행하고 다음 명령어를 수행합니다. + +``` +rrdb init ``` --- diff --git a/rrdb/database.config b/rrdb/database.config deleted file mode 100644 index 3ce2be93..00000000 Binary files a/rrdb/database.config and /dev/null differ diff --git a/src/command/init.rs b/src/command/init.rs index d834986a..7eb50334 100644 --- a/src/command/init.rs +++ b/src/command/init.rs @@ -4,11 +4,7 @@ use clap::Args; /// Config options for the build system. #[derive(Clone, Debug, Default, Deserialize, Args)] -pub struct ConfigOptionsInit { - /// 파일이 세팅될 경로 - #[clap(long, short)] - pub config_path: Option, -} +pub struct ConfigOptionsInit {} #[derive(Clone, Debug, Args)] #[clap(name = "init")] diff --git a/src/executor/executor.rs b/src/executor/executor.rs index a6e28a87..9b5a442c 100644 --- a/src/executor/executor.rs +++ b/src/executor/executor.rs @@ -1,13 +1,11 @@ -use path_absolutize::*; use std::error::Error; -use std::path::PathBuf; use crate::ast::ddl::create_database::CreateDatabaseQuery; use crate::ast::{DDLStatement, DMLStatement, OtherStatement, SQLStatement}; use crate::errors::execute_error::ExecuteError; use crate::executor::predule::ExecuteResult; use crate::logger::predule::Logger; -use crate::utils::predule::set_system_env; +use crate::utils::path::get_target_basepath; use super::config::global::GlobalConfig; @@ -25,26 +23,15 @@ impl Executor { } // 기본 설정파일 세팅 - pub async fn init(&self, path: String) -> Result<(), Box> { - let mut path_buf = PathBuf::new(); - path_buf.push(path); - path_buf.push(".rrdb.config"); - - #[allow(non_snake_case)] - let RRDB_BASE_PATH = path_buf - .absolutize() - .map_err(|e| ExecuteError::dyn_boxed(e.to_string()))? - .to_str() - .unwrap() - .to_string(); - set_system_env("RRDB_BASE_PATH", &RRDB_BASE_PATH); - - // 루트 디렉터리 생성 - let base_path = path_buf.clone(); + pub async fn init(&self) -> Result<(), Box> { + // 루트 디렉터리 생성 (없다면) + let base_path = get_target_basepath(); if let Err(error) = tokio::fs::create_dir(base_path.clone()).await { if error.kind() == std::io::ErrorKind::AlreadyExists { // Do Nothing } else { + println!("path {:?}", base_path.clone()); + println!("error: {:?}", error.to_string()); return Err(ExecuteError::boxed(error.to_string())); } } diff --git a/src/executor/util.rs b/src/executor/util.rs index 7c086a07..abb7e4ca 100644 --- a/src/executor/util.rs +++ b/src/executor/util.rs @@ -1,9 +1,9 @@ use std::path::PathBuf; -use crate::{executor::predule::Executor, utils::env::get_system_env}; +use crate::{executor::predule::Executor, utils::path::get_target_basepath}; impl Executor { pub fn get_base_path(&self) -> PathBuf { - PathBuf::from(get_system_env("RRDB_BASE_PATH")) + PathBuf::from(get_target_basepath()) } } diff --git a/src/main.rs b/src/main.rs index d71bf57b..92498281 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,12 +30,7 @@ async fn main() -> Result<(), Box> { let executor = Executor::new(); - let path = match init_option.config_path { - Some(path) => path, - None => ".".into(), - }; - - executor.init(path).await?; + executor.init().await?; } SubCommand::Run(run) => { let server_option = ServerOption { diff --git a/src/utils/env.rs b/src/utils/env.rs deleted file mode 100644 index d8ef84c6..00000000 --- a/src/utils/env.rs +++ /dev/null @@ -1,82 +0,0 @@ -// 운영 체제에 종속적인 형태로, 파일 저장경로 등에 대한 값을 환경변수로 저장합니다. -// Windows, Linux, MacOS를 위주로 지원합니다. - -// deprecated -// 환경변수를 가져옵니다. -pub fn get_system_env(_key: S) -> String { - "fo".to_string() - // let key = key.to_string(); - - // #[cfg(target_os = "windows")] - // { - // use winreg::{enums::HKEY_CURRENT_USER, RegKey}; - // let hkcu = RegKey::predef(HKEY_CURRENT_USER); - // let (env, _) = hkcu.create_subkey("Environment").unwrap(); // create_subkey opens with write permissions - // let value: String = env.get_value(key.as_str()).unwrap(); - - // value - // } - - // #[cfg(target_os = "linux")] - // { - // // use super::get_profile_path; - // // use std::process::Command; - // // use std::{fs, io::Write}; - // "fo".to_string() - // } - - // #[cfg(target_os = "macos")] - // { - // // use super::get_profile_path; - // // use std::process::Command; - // // use std::{fs, io::Write}; - // std::env::var(key).unwrap() - // } -} - -// deprecated -// 환경변수를 설정합니다. -pub fn set_system_env(_key: S, _value: S) { - // let key = key.to_string(); - // let value = value.to_string(); - - // #[cfg(target_os = "windows")] - // { - // use winreg::{enums::HKEY_CURRENT_USER, RegKey}; - // let hkcu = RegKey::predef(HKEY_CURRENT_USER); - // let (env, _) = hkcu.create_subkey("Environment").unwrap(); // create_subkey opens with write permissions - // env.set_value(&key, &value).unwrap(); - // } - - // #[cfg(target_os = "linux")] - // { - // // use super::get_profile_path; - // // use std::process::Command; - // // use std::{fs, io::Write}; - // } - - // #[cfg(target_os = "macos")] - // { - // use super::get_profile_path; - // use std::process::Command; - // use std::{fs, io::Write}; - - // let profile_path = get_profile_path(); - - // let mut file = fs::OpenOptions::new() - // .write(true) - // .append(true) - // .open(profile_path) - // .unwrap(); - - // let export_line = format!("export {}={}\n", key, value); - - // file.write_all(export_line.as_bytes()).unwrap(); - // std::env::set_var(key, value); - // Command::new("export FOO=\"BAR\"").output().unwrap(); - // // Command::new("export") - // // .arg(format!("{}={}", key, value)) - // // .spawn() - // // .unwrap(); - // } -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 09b012d0..424d8452 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,5 @@ pub mod collection; -pub mod env; +pub mod path; pub mod float; pub mod macos; pub mod predule; diff --git a/src/utils/path.rs b/src/utils/path.rs new file mode 100644 index 00000000..dba61c76 --- /dev/null +++ b/src/utils/path.rs @@ -0,0 +1,25 @@ +// 운영 체제에 종속적인 형태로, 파일 저장경로 등에 대한 값을 환경변수로 저장합니다. +// Windows, Linux, MacOS를 위주로 지원합니다. + +use std::{path::PathBuf, str::FromStr}; + +// 운영체제별 기본 저장 경로를 반환합니다. +// 현재는 Windows, Linux만 지원합니다. +#[allow(unreachable_code)] +pub fn get_target_basepath() -> PathBuf { + #[cfg(target_os = "windows")] + { + return PathBuf::from_str("C:\\Program Files\\rrdb").unwrap(); + } + + #[cfg(target_os = "linux")] + { + return PathBuf::from_str("/var/lib/rrdb").unwrap(); + } + + // #[cfg(target_os = "macos")] + // { + // } + + unimplemented!("Not supported OS"); +} diff --git a/src/utils/predule.rs b/src/utils/predule.rs index d873c21c..53ef6ad1 100644 --- a/src/utils/predule.rs +++ b/src/utils/predule.rs @@ -1,3 +1,3 @@ -pub use super::env::*; +pub use super::path::*; pub use super::float::*; pub use super::macos::*;