Skip to content

Commit

Permalink
Merge pull request #73 from myyrakle/refac/#67
Browse files Browse the repository at this point in the history
[#67] 저장경로를 절대경로로 변경
  • Loading branch information
wHoIsDReAmer authored Mar 18, 2024
2 parents b4fc394 + 540ce74 commit 33e3d6a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 116 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ cargo를 사용한다.
cargo install rrdb
```

- 플랫폼별 처리 (Linux)

심볼릭 링크를 생성하고 초기화를 수행합니다.

```
sudo ln -s /home/$USER/.cargo/bin/rrdb /usr/bin/rrdb
sudo rrdb init
```

- 플랫폼별 처리 (Windows)

powershell을 관리자 권한으로 실행하고 다음 명령어를 수행합니다.

```
rrdb init
```

---

### 기본 사용법
Expand Down
Binary file removed rrdb/database.config
Binary file not shown.
6 changes: 1 addition & 5 deletions src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
pub struct ConfigOptionsInit {}

#[derive(Clone, Debug, Args)]
#[clap(name = "init")]
Expand Down
25 changes: 6 additions & 19 deletions src/executor/executor.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -25,26 +23,15 @@ impl Executor {
}

// 기본 설정파일 세팅
pub async fn init(&self, path: String) -> Result<(), Box<dyn Error + Send>> {
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<dyn Error + Send>> {
// 루트 디렉터리 생성 (없다면)
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()));
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/executor/util.rs
Original file line number Diff line number Diff line change
@@ -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())
}
}
7 changes: 1 addition & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ async fn main() -> Result<(), Box<dyn Error + Send>> {

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 {
Expand Down
82 changes: 0 additions & 82 deletions src/utils/env.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod collection;
pub mod env;
pub mod path;
pub mod float;
pub mod macos;
pub mod predule;
25 changes: 25 additions & 0 deletions src/utils/path.rs
Original file line number Diff line number Diff line change
@@ -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");
}
2 changes: 1 addition & 1 deletion src/utils/predule.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub use super::env::*;
pub use super::path::*;
pub use super::float::*;
pub use super::macos::*;

0 comments on commit 33e3d6a

Please sign in to comment.