From 9a6ad0e67b52e419c8a1c59c9cd187d1b85cd9f8 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 1 May 2022 13:56:13 +0300 Subject: chore: code cleanup --- Cargo.lock | 55 ------------------------------------------------ Cargo.toml | 1 - src/database/file/mod.rs | 16 ++++++-------- 3 files changed, 6 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2effcfe..ad2e110 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -930,17 +930,6 @@ dependencies = [ "instant", ] -[[package]] -name = "fd-lock" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc110fe50727d46a428eed832df40affe9bf74d077cac1bf3f2718e823f14c5" -dependencies = [ - "cfg-if", - "libc", - "windows-sys", -] - [[package]] name = "fixedbitset" version = "0.2.0" @@ -1551,7 +1540,6 @@ dependencies = [ "either", "ellipse", "env_logger 0.8.4", - "fd-lock", "futures", "futures-util", "http-types", @@ -3844,49 +3832,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82ca39602d5cbfa692c4b67e3bcbb2751477355141c1ed434c94da4186836ff6" -dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_msvc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52695a41e536859d5308cc613b4a022261a274390b25bd29dfff4bf08505f3c2" - -[[package]] -name = "windows_i686_gnu" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54725ac23affef038fecb177de6c9bf065787c2f432f79e3c373da92f3e1d8a" - -[[package]] -name = "windows_i686_msvc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d5158a43cc43623c0729d1ad6647e62fa384a3d135fd15108d37c683461f64" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc31f409f565611535130cfe7ee8e6655d3fa99c1c61013981e491921b5ce954" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f2b8c7cbd3bfdddd9ab98769f9746a7fad1bca236554cd032b78d768bc0e89f" - [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index 61b100e..f8dbd6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,6 @@ easy-scraper = "^0.2.0" # HTML scraping library focused on ease of use either = "^1.6.1" # A general purpose sum type with two cases ellipse = "^0.2.0" # Truncate and ellipsize strings in a human-friendly way env_logger = "^0.8.3" # A logging implementation for `log` which is configured via an environment variable -fd-lock = "^3.0.0" # Advisory reader-writer locks for files futures = "^0.3.14" # An implementation of futures and streams futures-util = "^0.3.14" # Common utilities and extension traits for the futures-rs library lazy_static = "^1.4.0" # A macro for declaring lazily evaluated statics in Rust diff --git a/src/database/file/mod.rs b/src/database/file/mod.rs index 53dea04..853240a 100644 --- a/src/database/file/mod.rs +++ b/src/database/file/mod.rs @@ -5,9 +5,6 @@ use tokio::fs::{File, OpenOptions}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::task::spawn_blocking; use async_trait::async_trait; -/*use futures_util::stream; -use futures_util::StreamExt; -use futures_util::TryStreamExt;*/ use futures::{stream, StreamExt, TryStreamExt}; use log::debug; use serde_json::json; @@ -111,7 +108,7 @@ fn url_to_path(root: &Path, url: &str) -> PathBuf { fn url_to_relative_path(url: &str) -> relative_path::RelativePathBuf { let url = warp::http::Uri::try_from(url).expect("Couldn't parse a URL"); let mut path = relative_path::RelativePathBuf::new(); - path.push(url.authority().unwrap().to_string() + &url.path().to_string() + ".json"); + path.push(url.authority().unwrap().to_string() + url.path() + ".json"); path } @@ -402,12 +399,11 @@ impl Storage for FileStorage { let mut content = String::new(); file.read_to_string(&mut content).await?; drop(file); - let mut channels: Vec; - if !content.is_empty() { - channels = serde_json::from_str(&content)?; + let mut channels: Vec = if !content.is_empty() { + serde_json::from_str(&content)? } else { - channels = Vec::default(); - } + Vec::default() + }; channels.push(super::MicropubChannel { uid: key.to_string(), @@ -614,6 +610,6 @@ impl Storage for FileStorage { tempfile.write_all(serde_json::to_string(&settings)?.as_bytes()).await?; drop(tempfile); tokio::fs::rename(temppath, path).await?; - Result::Ok(()) + Ok(()) } } -- cgit 1.4.1