handle non-existing pacdef-related dirs
This commit is contained in:
@@ -46,6 +46,13 @@ impl Config {
|
||||
let result = Self::default();
|
||||
|
||||
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")?;
|
||||
write!(output, "{content}").context("writing default config")?;
|
||||
|
||||
|
||||
@@ -29,6 +29,13 @@ impl Group {
|
||||
pub fn load(group_dir: &Path, warn_not_symlinks: bool) -> Result<HashSet<Self>> {
|
||||
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")? {
|
||||
let file = entry.context("getting group file")?;
|
||||
let path = file.path();
|
||||
@@ -46,6 +53,10 @@ impl Group {
|
||||
result.insert(group);
|
||||
}
|
||||
|
||||
if result.is_empty() {
|
||||
eprintln!("WARNING: no group files found");
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user