-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
43 additions
and
24 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
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 |
---|---|---|
@@ -1,39 +1,50 @@ | ||
use anyhow::{anyhow, Result}; | ||
use std::{env, fs, path::PathBuf}; | ||
|
||
fn main() { | ||
let home = env::var("HOME").expect("Error getting HOME env."); | ||
|
||
let mut crescent_dir = PathBuf::from(home); | ||
// This build file creates the ~/.crescent/profiles directories and | ||
// copies the default profiles in ./profiles to ~/.crescent/profiles. | ||
fn main() -> Result<()> { | ||
let home_dir = match env::var("HOME") { | ||
Ok(dir) => dir, | ||
Err(err) => return Err(anyhow!("Error retrieving HOME directory: {err}")), | ||
}; | ||
|
||
let mut crescent_dir = PathBuf::from(home_dir); | ||
crescent_dir.push(".crescent/profiles"); | ||
|
||
if !crescent_dir.exists() { | ||
fs::create_dir_all(&crescent_dir).expect("Error creating crescent and profiles directory."); | ||
if let Err(err) = fs::create_dir_all(&crescent_dir) { | ||
return Err(anyhow!( | ||
"Error creating crescent and profiles directory: {err}" | ||
)); | ||
} | ||
} | ||
|
||
let base_profiles_dir = PathBuf::from("./profiles"); | ||
|
||
let base_profiles = base_profiles_dir | ||
.read_dir() | ||
.expect("Error reading base profiles directory.") | ||
.flatten(); | ||
let default_profiles_dir = PathBuf::from("./profiles"); | ||
let default_profiles = match default_profiles_dir.read_dir() { | ||
Ok(dir) => dir.flatten(), | ||
Err(err) => return Err(anyhow!("Error reading default profiles directory: {err}")), | ||
}; | ||
|
||
'base_loop: for base_profile in base_profiles { | ||
let user_profiles = crescent_dir | ||
.read_dir() | ||
.expect("Error reading user profiles directory.") | ||
.flatten(); | ||
'base_loop: for default_profile in default_profiles { | ||
let user_profiles = match crescent_dir.read_dir() { | ||
Ok(dir) => dir.flatten(), | ||
Err(err) => return Err(anyhow!("Error reading default user directory: {err}")), | ||
}; | ||
|
||
for user_profile in user_profiles { | ||
if user_profile.file_name() == base_profile.file_name() { | ||
if user_profile.file_name() == default_profile.file_name() { | ||
continue 'base_loop; | ||
} | ||
} | ||
|
||
fs::copy( | ||
base_profile.path(), | ||
crescent_dir.join(base_profile.file_name()), | ||
) | ||
.expect("Error copying profile."); | ||
if let Err(err) = fs::copy( | ||
default_profile.path(), | ||
crescent_dir.join(default_profile.file_name()), | ||
) { | ||
return Err(anyhow!("Error copying profile: {err}")); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
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