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") (jobs-dir "/etc/rori.kron")
(debug t) (debug t)
(allow (allow :all)
:all) (deny
(deny (:user "flon")
(:user "flon") (:uid 8008))
(:uid 8008)))

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

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

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

Loading…
Cancel
Save