From 69d3e0e6564b416637978a69f0a035066aea4759 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Wed, 10 Apr 2024 20:15:39 +0200 Subject: Closes #30 and #27. At least a little --- src/storage.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/storage.rs') diff --git a/src/storage.rs b/src/storage.rs index 6ba5ee1..0da245b 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -8,7 +8,7 @@ use ipnetwork::IpNetwork; use mac_address::MacAddress; use serde::{Deserialize, Serialize}; use serde_json::json; -use tracing::{debug, warn}; +use tracing::{debug, trace, warn}; use utoipa::ToSchema; use crate::error::Error; @@ -26,6 +26,7 @@ impl Device { const STORAGE_PATH: &'static str = "devices"; pub fn setup() -> Result { + trace!("check for storage at {}", Self::STORAGE_PATH); let sp = Path::new(Self::STORAGE_PATH); if !sp.exists() { warn!("device storage path doesn't exist, creating it"); @@ -38,17 +39,21 @@ impl Device { } pub fn read(id: &str) -> Result { + trace!(?id, "attempt to read file"); let mut file = File::open(format!("{}/{id}.json", Self::STORAGE_PATH))?; let mut buf = String::new(); file.read_to_string(&mut buf)?; + trace!(?id, ?buf, "read successfully from file"); let dev = serde_json::from_str(&buf)?; Ok(dev) } pub fn write(&self) -> Result<(), Error> { + trace!(?self.id, ?self, "attempt to write to file"); let mut file = File::create(format!("{}/{}.json", Self::STORAGE_PATH, self.id))?; file.write_all(json!(self).to_string().as_bytes())?; + trace!(?self.id, "wrote successfully to file"); Ok(()) } -- cgit v1.2.3