being wonk is fine actually

master
Avril 4 years ago
parent e161688fc0
commit b813fe4b01
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,7 +1,6 @@
((jobs-dir "/etc/rori.kron")
(debug t)
(allow
:all)
(deny
(:user "flon")
(:uid 8008)))
(jobs-dir "/etc/rori.kron")
(debug t)
(allow :all)
(deny
(:user "flon")
(:uid 8008))

@ -5,16 +5,30 @@ use std::{
path::PathBuf,
};
//TODO: Embed info about the file, the line number, the expression, etc?
/// Error type for parsing config errors
#[derive(Debug)]
pub enum Error {
/// Internal IO error
IO(io::Error),
/// S-expression syntax error
Syntax(sexp::Error),
/// File not found, or was a directory
NotFound(PathBuf),
/// File contained invalid UTF-8
InvalidUtf8,
/// Invalid or unexpected type
TypeError{expected:LispType, got: LispType},
/// Expected a list with at least one element
UnexpectedEmpty,
UnknownDefinition(String),
/// Unknown definition string
UnknownDefinition(String),
/// Non-descript other error
Unknown,
}

@ -13,6 +13,8 @@ pub enum LispType
String,
Integer,
Float,
/// A non-descript atom, either String, Integer, Float, or the empty list.
Atom,
}
@ -85,7 +87,7 @@ impl std::fmt::Display for LispType
Self::String => "string",
Self::Integer => "integer",
Self::Float => "float",
Self::Atom => "atom",
Self::Atom => "nil",
})
}
}

@ -2,10 +2,12 @@
use super::*;
use std::{
convert::TryFrom,
marker::Unpin,
};
use tokio::{
prelude::*,
fs::File,
io::AsyncRead,
};
use sexp::{
Sexp,
@ -61,12 +63,15 @@ pub async fn global(to: &mut Config, path: impl AsRef<Path>) -> Result<(), error
let mut contents = if let Ok(Ok(wv)) = file.metadata().await
.map(|x| x.len())
.map(|x| usize::try_from(x)) {
Vec::with_capacity(wv)
let mut out = Vec::with_capacity(wv+3);
out.push(b'(');
out
} else {
Vec::new()
vec![b'(']
};
file.read_to_end(&mut contents).await?;
file.read_to_end(&mut contents).await?;
contents.push(b')');
let parsed = sexp::parse(std::str::from_utf8(&contents[..])?)?;
let sexp = parsed.try_into_list()?;

Loading…
Cancel
Save