diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -28,14 +28,14 @@ pub struct Db { | |||
28 | 28 | ||
29 | impl Db { | 29 | impl Db { |
30 | pub fn new(config: Config) -> Self { | 30 | pub fn new(config: Config) -> Self { |
31 | fs::create_dir_all("blocks").unwrap(); | 31 | fs::create_dir_all(format!("blocks/{}", config.name)).unwrap(); |
32 | fs::create_dir_all("users").unwrap(); | 32 | fs::create_dir_all(format!("users/{}", config.name)).unwrap(); |
33 | let mut db = Db::default(); | 33 | let mut db = Db::default(); |
34 | if let Some(block_path) = last_block_content() { | 34 | if let Some(block_path) = last_block_content(&config.name) { |
35 | db.populate_with_last_block(block_path); | 35 | db.populate_with_last_block(block_path); |
36 | } | 36 | } |
37 | 37 | ||
38 | if let Ok(users_path) = read_users() { | 38 | if let Ok(users_path) = read_users(&config.name) { |
39 | db.populate_with_users(users_path); | 39 | db.populate_with_users(users_path); |
40 | } | 40 | } |
41 | 41 | ||
@@ -85,8 +85,8 @@ impl Db { | |||
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | fn last_block_content() -> Option<String> { | 88 | fn last_block_content(config_name: &str) -> Option<String> { |
89 | let blocks = read_block_name().unwrap(); | 89 | let blocks = read_block_name(config_name).unwrap(); |
90 | 90 | ||
91 | if blocks.is_empty() { | 91 | if blocks.is_empty() { |
92 | return None; | 92 | return None; |
@@ -107,8 +107,9 @@ fn last_block_content() -> Option<String> { | |||
107 | return Some(blocks[last_block_index].to_str().unwrap().parse().unwrap()); | 107 | return Some(blocks[last_block_index].to_str().unwrap().parse().unwrap()); |
108 | } | 108 | } |
109 | 109 | ||
110 | fn read_block_name() -> io::Result<Vec<PathBuf>> { | 110 | fn read_block_name(config_name: &str) -> io::Result<Vec<PathBuf>> { |
111 | let entries = fs::read_dir("./blocks")? | 111 | let path = format!("./blocks/{}", config_name); |
112 | let entries = fs::read_dir(path)? | ||
112 | .map(|res| res.map(|e| e.path())) | 113 | .map(|res| res.map(|e| e.path())) |
113 | .collect::<Result<Vec<_>, io::Error>>()?; | 114 | .collect::<Result<Vec<_>, io::Error>>()?; |
114 | 115 | ||
@@ -122,8 +123,9 @@ fn parse_block(path: &str) -> u64 { | |||
122 | block_u64 | 123 | block_u64 |
123 | } | 124 | } |
124 | 125 | ||
125 | fn read_users() -> io::Result<Vec<PathBuf>> { | 126 | fn read_users(config_name: &str) -> io::Result<Vec<PathBuf>> { |
126 | let entries = fs::read_dir("./users")? | 127 | let path = format!("./users/{}", config_name); |
128 | let entries = fs::read_dir(path)? | ||
127 | .map(|res| res.map(|e| e.path())) | 129 | .map(|res| res.map(|e| e.path())) |
128 | .collect::<Result<Vec<_>, io::Error>>()?; | 130 | .collect::<Result<Vec<_>, io::Error>>()?; |
129 | 131 | ||