remove canonicalize
This commit is contained in:
parent
e925895eab
commit
ad67d5997a
@ -36,6 +36,7 @@ pub mod cli {
|
|||||||
ImportMiniMoonboardProblems {
|
ImportMiniMoonboardProblems {
|
||||||
file_path: PathBuf,
|
file_path: PathBuf,
|
||||||
},
|
},
|
||||||
|
// TODO: idempotent state initialization to be used in systemd preStart hook
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ fn file_service(path: impl AsRef<Path>) -> ServeDir {
|
|||||||
async fn load_state() -> Result<State, Error> {
|
async fn load_state() -> Result<State, Error> {
|
||||||
tracing::info!("Loading state");
|
tracing::info!("Loading state");
|
||||||
let state = State {
|
let state = State {
|
||||||
persistent: Persistent::<PersistentState>::load(STATE_FILE.into()).await?,
|
persistent: Persistent::<PersistentState>::load(&Path::new(STATE_FILE)).await?,
|
||||||
};
|
};
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -23,29 +23,25 @@ impl<T> Persistent<T> {
|
|||||||
|
|
||||||
/// Instantiates state from file system
|
/// Instantiates state from file system
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
pub async fn load(file_path: Utf8PathBuf) -> Result<Self, Error>
|
pub async fn load(file_path: &Path) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
{
|
{
|
||||||
let file_path = file_path.canonicalize().map_err(|source| Error::BadPath {
|
|
||||||
path: file_path.clone(),
|
|
||||||
source,
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let content = tokio::fs::read_to_string(&file_path).await.map_err(|source| Error::Read {
|
let content = tokio::fs::read_to_string(&file_path).await.map_err(|source| Error::Read {
|
||||||
file_path: file_path.clone(),
|
file_path: file_path.to_owned(),
|
||||||
source,
|
source,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let t = ron::from_str(&content).map_err(|source| Error::Deserialize {
|
let t = ron::from_str(&content).map_err(|source| Error::Deserialize {
|
||||||
file_path: file_path.clone(),
|
file_path: file_path.to_owned(),
|
||||||
source,
|
source,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let persistent = Self {
|
let persistent = Self {
|
||||||
state: Arc::new(Mutex::new(t)),
|
state: Arc::new(Mutex::new(t)),
|
||||||
file_path,
|
file_path: file_path.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(persistent)
|
Ok(persistent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +112,6 @@ impl<T> Persistent<T> {
|
|||||||
#[derive(Debug, derive_more::Error, derive_more::Display)]
|
#[derive(Debug, derive_more::Error, derive_more::Display)]
|
||||||
#[display("Persistent state error: {_variant}")]
|
#[display("Persistent state error: {_variant}")]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[display("Failed to operate on path: {path}")]
|
|
||||||
BadPath { path: Utf8PathBuf, source: std::io::Error },
|
|
||||||
|
|
||||||
#[display("Failed to read file: {}", file_path.display())]
|
#[display("Failed to read file: {}", file_path.display())]
|
||||||
Read { file_path: PathBuf, source: std::io::Error },
|
Read { file_path: PathBuf, source: std::io::Error },
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user