B:BD[
4.90062] → [
10.12751:12811]
∅:D[
10.12811] → [
9.544:597]
B:BD[
4.90115] → [
9.544:597]
∅:D[
9.597] → [
4.90206:90243]
B:BD[
4.90206] → [
4.90206:90243]
B:BD[
4.90243] → [
10.12812:12925]
∅:D[
10.12925] → [
11.60:357]
B:BD[
11.60] → [
11.60:357]
B:BD[
11.357] → [
10.12926:13018]
∅:D[
10.13018] → [
11.401:594]
B:BD[
11.401] → [
11.401:594]
∅:D[
11.594] → [
4.90370:90437]
B:BD[
4.90370] → [
4.90370:90437]
B:BD[
4.90437] → [
9.598:651]
B:BD[
9.651] → [
10.13019:13111]
∅:D[
11.639] → [
4.90532:90561]
∅:D[
10.13111] → [
4.90532:90561]
B:BD[
4.90532] → [
4.90532:90561]
B:BD[
4.90561] → [
11.640:678]
∅:D[
11.678] → [
4.90607:90629]
B:BD[
4.90607] → [
4.90607:90629]
B:BD[
4.90629] → [
11.679:700]
∅:D[
11.700] → [
4.90662:90697]
B:BD[
4.90662] → [
4.90662:90697]
B:BD[
4.90697] → [
7.11467:11517]
B:BD[
7.11517] → [
10.13112:13336]
∅:D[
10.13336] → [
7.11539:11646]
B:BD[
7.11539] → [
7.11539:11646]
∅:D[
11.794] → [
4.90881:90898]
∅:D[
7.11646] → [
4.90881:90898]
B:BD[
4.90881] → [
4.90881:90898]
B:BD[
4.90898] → [
7.11647:11702]
∅:D[
11.844] → [
4.90954:90964]
∅:D[
7.11702] → [
4.90954:90964]
B:BD[
4.90954] → [
4.90954:90964]
pub fn load() -> Result<(Global, u64), anyhow::Error> {
if let Some(mut dir) = global_config_dir() {
dir.push("config.toml");
let (s, meta) = std::fs::read(&dir)
.and_then(|x| Ok((x, std::fs::metadata(&dir)?)))
.or_else(|e| {
// Read from `$HOME/.config/pijul` dir
if let Some(mut dir) = dirs_next::home_dir() {
dir.push(".config");
dir.push(CONFIG_DIR);
dir.push("config.toml");
std::fs::read(&dir).and_then(|x| Ok((x, std::fs::metadata(&dir)?)))
} else {
Err(e.into())
}
})
.or_else(|e| {
// Read from `$HOME/.pijulconfig`
if let Some(mut dir) = dirs_next::home_dir() {
dir.push(GLOBAL_CONFIG_DIR);
std::fs::read(&dir).and_then(|x| Ok((x, std::fs::metadata(&dir)?)))
} else {
Err(e.into())
}
})?;
debug!("s = {:?}", s);
if let Ok(t) = toml::from_slice(&s) {
let ts = meta
.modified()?
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs();
Ok((t, ts))
} else {
bail!("Could not read configuration file at {:?}", dir)
}
} else {
bail!("Global configuration file missing")
}
pub fn load() -> Result<(Global, Option<u64>), anyhow::Error> {
let res = None
.or_else(|| {
let mut path = global_config_dir()?;
path.push("config.toml");
try_load_file(path)
})
.or_else(|| {
// Read from `$HOME/.config/pijul` dir
let mut path = dirs_next::home_dir()?;
path.push(".config");
path.push(CONFIG_DIR);
path.push("config.toml");
try_load_file(path)
})
.or_else(|| {
// Read from `$HOME/.pijulconfig`
let mut path = dirs_next::home_dir()?;
path.push(GLOBAL_CONFIG_DIR);
try_load_file(path)
});
let Some((file, path)) = res else {
return Ok((Global::default(), None));
};
let mut file = file.map_err(|e| {
anyhow!("Could not open configuration file at {}", path.display()).context(e)
})?;
let mut buf = String::new();
file.read_to_string(&mut buf).map_err(|e| {
anyhow!("Could not read configuration file at {}", path.display()).context(e)
})?;
debug!("buf = {:?}", buf);
let global: Global = toml::from_str(&buf).map_err(|e| {
anyhow!("Could not parse configuration file at {}", path.display()).context(e)
})?;
let metadata = file.metadata()?;
let file_age = metadata
.modified()?
.duration_since(std::time::SystemTime::UNIX_EPOCH)?
.as_secs();
Ok((global, Some(file_age)))