Skip to content
Snippets Groups Projects
Commit adb6ae42 authored by Evy Storozhenko's avatar Evy Storozhenko
Browse files

fixed relative paths

parent 697f5986
No related branches found
No related tags found
No related merge requests found
Pipeline #253759 passed
use anyhow::Context; use anyhow::Context;
use minijinja::Environment; use minijinja::Environment;
use std::{collections::HashMap, fs, path::Path}; use std::{
collections::HashMap,
fs,
path::{Path, PathBuf},
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::json; use serde_json::json;
...@@ -33,15 +37,26 @@ pub struct Config { ...@@ -33,15 +37,26 @@ pub struct Config {
impl Config { impl Config {
pub fn new(config_path: impl AsRef<Path>) -> anyhow::Result<Self> { pub fn new(config_path: impl AsRef<Path>) -> anyhow::Result<Self> {
let mut config: Config = serde_yaml::from_str( let mut config: Config = serde_yaml::from_str(
&fs::read_to_string(config_path).with_context(|| "config not found".to_string())?, &fs::read_to_string(&config_path).with_context(|| "config not found".to_string())?,
)?; )?;
let additional_files = config.files.clone().unwrap_or_default(); if let Some(ref additional_paths) = config.files {
for file in additional_files { let base_path = config_path.as_ref().parent().unwrap();
let mut additional_links: Vec<Shortlink> = serde_yaml::from_str( let actual_paths: Vec<PathBuf> = additional_paths
&fs::read_to_string(file) .iter()
.with_context(|| "additional shortlink file not found".to_string())?, .map(|path_str| {
)?; let path = PathBuf::from(&path_str);
config.shortlinks.append(&mut additional_links); if path.is_absolute() {
path
} else {
base_path.join(path)
}
})
.collect();
for path in actual_paths {
config
.shortlinks
.append(&mut serde_yaml::from_str(&fs::read_to_string(&path)?)?);
}
} }
Ok(config) Ok(config)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment