about summary refs log tree commit diff
path: root/src/database/file
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/file')
-rw-r--r--src/database/file/mod.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs
index da8a06a..d1227d8 100644
--- a/src/database/file/mod.rs
+++ b/src/database/file/mod.rs
@@ -196,7 +196,7 @@ fn modify_post(post: &serde_json::Value, update: &serde_json::Value) -> Result<s
     Ok(post)
 }
 
-#[derive(Clone)]
+#[derive(Clone, Debug)]
 /// A backend using a folder with JSON files as a backing store.
 /// Uses symbolic links to represent a many-to-one mapping of URLs to a post.
 pub struct FileStorage {
@@ -271,11 +271,12 @@ impl Storage for FileStorage {
                     let lock = RwLock::new(file);
                     debug!("Trying to get a lock for file {:?}", &path);
                     let guard = lock.read()?;
-
+                    debug!("Lock for {:?} acquired", &path);
                     let mut content = String::new();
                     // Typechecks because OS magic acts on references
                     // to FDs as if they were behind a mutex
                     (&mut &*guard).read_to_string(&mut content)?;
+                    debug!("Read {} bytes successfully from {:?}", content.as_bytes().len(), &path);
                     Ok(Some(serde_json::from_str(&content)?))
                 }
                 Err(err) => {
@@ -291,7 +292,7 @@ impl Storage for FileStorage {
         })).await?.unwrap()
     }
 
-    async fn put_post<'a>(&self, post: &'a serde_json::Value, user: &'a str) -> Result<()> {
+    async fn put_post(&self, post: &'_ serde_json::Value, user: &'_ str) -> Result<()> {
         let key = post["properties"]["uid"][0]
             .as_str()
             .expect("Tried to save a post without UID");
@@ -384,6 +385,7 @@ impl Storage for FileStorage {
                 .map(|s| s.to_string())
                 .unwrap_or_else(String::default);
             let key = key.to_string();
+            #[allow(clippy::drop_ref)] // using drop() to prevent mistakes here
             drop(post);
             tokio::time::timeout(Duration::from_secs(IO_TIMEOUT), spawn_blocking(move || {
                 let file = OpenOptions::new()
@@ -421,7 +423,7 @@ impl Storage for FileStorage {
         Ok(())
     }
 
-    async fn update_post<'a>(&self, url: &'a str, update: serde_json::Value) -> Result<()> {
+    async fn update_post(&self, url: &'_ str, update: serde_json::Value) -> Result<()> {
         let path = url_to_path(&self.root_dir, url);
         #[allow(unused_variables)]
         let (old_json, new_json) = tokio::time::timeout(
@@ -454,7 +456,7 @@ impl Storage for FileStorage {
         Ok(())
     }
 
-    async fn get_channels<'a>(&self, user: &'a str) -> Result<Vec<super::MicropubChannel>> {
+    async fn get_channels(&self, user: &'_ str) -> Result<Vec<super::MicropubChannel>> {
         let mut path = relative_path::RelativePathBuf::new();
         path.push(warp::http::Uri::try_from(user.to_string()).unwrap().authority().unwrap().to_string());
         path.push("channels");
@@ -486,12 +488,12 @@ impl Storage for FileStorage {
         })).await?.unwrap()
     }
 
-    async fn read_feed_with_limit<'a>(
+    async fn read_feed_with_limit(
         &self,
-        url: &'a str,
-        after: &'a Option<String>,
+        url: &'_ str,
+        after: &'_ Option<String>,
         limit: usize,
-        user: &'a Option<String>,
+        user: &'_ Option<String>,
     ) -> Result<Option<serde_json::Value>> {
         if let Some(feed) = self.get_post(url).await? {
             if let Some(mut feed) = filter_post(feed, user) {
@@ -545,7 +547,7 @@ impl Storage for FileStorage {
         }
     }
 
-    async fn delete_post<'a>(&self, url: &'a str) -> Result<()> {
+    async fn delete_post(&self, url: &'_ str) -> Result<()> {
         let path = url_to_path(&self.root_dir, url);
         if let Err(e) = tokio::fs::remove_file(path).await {
             Err(e.into())
@@ -555,7 +557,7 @@ impl Storage for FileStorage {
         }
     }
 
-    async fn get_setting<'a>(&self, setting: &'a str, user: &'a str) -> Result<String> {
+    async fn get_setting(&self, setting: &'_ str, user: &'_ str) -> Result<String> {
         log::debug!("User for getting settings: {}", user);
         let url = http_types::Url::parse(user).expect("Couldn't parse a URL");
         let mut path = relative_path::RelativePathBuf::new();
@@ -581,7 +583,7 @@ impl Storage for FileStorage {
         })).await?.unwrap()
     }
 
-    async fn set_setting<'a>(&self, setting: &'a str, user: &'a str, value: &'a str) -> Result<()> {
+    async fn set_setting(&self, setting: &'_ str, user: &'_ str, value: &'_ str) -> Result<()> {
         let url = http_types::Url::parse(user).expect("Couldn't parse a URL");
         let mut path = relative_path::RelativePathBuf::new();
         path.push(url.origin().ascii_serialization());
@@ -618,7 +620,7 @@ impl Storage for FileStorage {
 
             settings.insert(setting.to_string(), value.to_string());
             (&mut *guard).seek(SeekFrom::Start(0))?;
-            (&mut *guard).set_len(0)?;
+            (*guard).set_len(0)?;
             (&mut *guard).write_all(serde_json::to_string(&settings)?.as_bytes())?;
             Result::Ok(())
         })).await?.unwrap()