handle non-existing pacdef-related dirs

This commit is contained in:
steven-omaha
2023-02-15 15:52:56 +01:00
parent 9e0913ef25
commit 9c512073b8
2 changed files with 18 additions and 0 deletions
+7
View File
@@ -46,6 +46,13 @@ impl Config {
let result = Self::default(); let result = Self::default();
let content = serde_yaml::to_string(&result).context("converting Config to yaml")?; let content = serde_yaml::to_string(&result).context("converting Config to yaml")?;
let parent = file.parent().context("getting parent of config dir")?;
if !parent.is_dir() {
std::fs::create_dir_all(parent)
.with_context(|| format!("creating dir {}", parent.to_string_lossy()))?;
}
let mut output = File::create(file).context("creating default config file")?; let mut output = File::create(file).context("creating default config file")?;
write!(output, "{content}").context("writing default config")?; write!(output, "{content}").context("writing default config")?;
+11
View File
@@ -29,6 +29,13 @@ impl Group {
pub fn load(group_dir: &Path, warn_not_symlinks: bool) -> Result<HashSet<Self>> { pub fn load(group_dir: &Path, warn_not_symlinks: bool) -> Result<HashSet<Self>> {
let mut result = HashSet::new(); let mut result = HashSet::new();
if !group_dir.is_dir() {
// we only need to create the innermost dir. The rest was already created from when
// we loaded the config
std::fs::create_dir(group_dir)
.with_context(|| format!("creating group dir {}", group_dir.to_string_lossy()))?;
}
for entry in group_dir.read_dir().context("reading group dir")? { for entry in group_dir.read_dir().context("reading group dir")? {
let file = entry.context("getting group file")?; let file = entry.context("getting group file")?;
let path = file.path(); let path = file.path();
@@ -46,6 +53,10 @@ impl Group {
result.insert(group); result.insert(group);
} }
if result.is_empty() {
eprintln!("WARNING: no group files found");
}
Ok(result) Ok(result)
} }
} }