-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6995be1
commit c09d14d
Showing
5 changed files
with
73 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::collections::HashMap; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
pub fn get_directory_structure( | ||
directory_path: &str, | ||
) -> HashMap<String, Vec<HashMap<String, String>>> { | ||
let path: &Path = Path::new(directory_path); | ||
|
||
if path.is_dir() { | ||
let mut result: HashMap<String, Vec<HashMap<String, String>>> = HashMap::new(); | ||
let mut files: Vec<HashMap<String, String>> = Vec::new(); | ||
|
||
if let Ok(entries) = fs::read_dir(path) { | ||
for entry in entries { | ||
if let Ok(entry) = entry { | ||
let file_name: String = entry.file_name().to_string_lossy().into_owned(); | ||
let file_path: std::path::PathBuf = entry.path(); | ||
|
||
let is_directory: bool = file_path.is_dir(); | ||
|
||
let mut file_info: HashMap<String, String> = HashMap::new(); | ||
file_info.insert("name".to_string(), file_name.clone()); | ||
file_info.insert("is_directory".to_string(), is_directory.to_string()); | ||
file_info.insert("is_read".to_string(), "false".to_string()); | ||
|
||
if is_directory { | ||
let subdirectory_structure: HashMap<String, Vec<HashMap<String, String>>> = | ||
get_directory_structure(&file_path.to_string_lossy()); | ||
file_info.insert( | ||
"contents".to_string(), | ||
serde_json::to_string(&subdirectory_structure).unwrap(), | ||
); | ||
} | ||
|
||
files.push(file_info); | ||
} | ||
} | ||
} | ||
|
||
result.insert("contents".to_string(), files); | ||
result | ||
} else { | ||
HashMap::new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod utils; | ||
pub mod sync_dir; | ||
pub mod dir_structure; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use std::fs::read_to_string; | ||
use std::path::Path; | ||
|
||
|
||
pub fn read_vault_ignore() -> Vec<String> { | ||
let filename: &str = ".vaultignore"; | ||
let path: &Path = Path::new(filename); | ||
let mut result: Vec<String> = Vec::new(); | ||
if path.exists() { | ||
for line in read_to_string(filename).unwrap().lines() { | ||
result.push(line.to_string()) | ||
} | ||
} | ||
result | ||
} |