From 28c6fa93b61ce44aef8cbab000a9b85e3b90fbe5 Mon Sep 17 00:00:00 2001 From: AB Date: Fri, 5 Jun 2020 02:29:07 +0300 Subject: [PATCH] Lint. --- src/filesystem.rs | 15 ++++++++------- src/http.rs | 37 +++++++++++++++++-------------------- src/main.rs | 6 +----- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/filesystem.rs b/src/filesystem.rs index a8a7470..2382a00 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,8 +12,8 @@ use polyfuse::{ }; use slab::Slab; - -use std::path::{PathBuf, Path}; +use crate::http::HTTP; +use std::path::{Path, PathBuf}; use std::{ collections::hash_map::{Entry, HashMap}, ffi::{OsStr, OsString}, @@ -24,7 +24,6 @@ use std::{ }; use tokio::sync::Mutex; use tracing_futures::Instrument; -use crate::http::HTTP; type Ino = u64; @@ -174,7 +173,11 @@ impl MemFS { }); Self { - http: HTTP::new(cfg.server.clone(), cfg.username.clone(), cfg.password.clone()), + http: HTTP::new( + cfg.server.clone(), + cfg.username.clone(), + cfg.password.clone(), + ), inodes: Mutex::new(inodes), f_ino_map: Mutex::new(Vec::new()), dir_handles: Mutex::default(), @@ -426,7 +429,6 @@ impl MemFS { let mut file_path = self.full_path(op.parent()).await.unwrap(); file_path.push(op.name()); self.fetch_remote(file_path, f_inode).await; - } _ => { drop(inode); @@ -613,7 +615,7 @@ impl MemFS { warn!("inode_mutex {:?}", inode_mutex); Some((uri, parent_ino)) } - INodeKind::Symlink(_) => Some((uri, parent_ino)) + INodeKind::Symlink(_) => Some((uri, parent_ino)), }; ret } @@ -868,7 +870,6 @@ impl MemFS { } async fn do_read(&self, op: &op::Read<'_>) -> io::Result { - let full_path_mutex = self.f_ino_map.lock().await; let mut counter = 0; let full_path = loop { diff --git a/src/http.rs b/src/http.rs index 8b2a90e..e90e277 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,5 +1,7 @@ extern crate base64; +use chrono::DateTime; +use reqwest::{header, Client, Error}; use serde::Deserialize; use std::{ path::PathBuf, @@ -7,14 +9,8 @@ use std::{ thread::sleep, time::{Duration, SystemTime}, }; -use chrono::{DateTime}; -use reqwest::{Client, Error, header}; -static APP_USER_AGENT: &str = concat!( -env!("CARGO_PKG_NAME"), -"/", -env!("CARGO_PKG_VERSION"), -); +static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); #[derive(Default, Debug, Clone)] pub struct HTTP { @@ -38,7 +34,7 @@ impl RemoteEntry { } impl HTTP { - pub fn new(server: String, username: Option, password: Option, ) -> Self { + pub fn new(server: String, username: Option, password: Option) -> Self { let mut headers = header::HeaderMap::new(); match username { Some(username) => { @@ -47,19 +43,19 @@ impl HTTP { _buf.push_str(format!("{}:{}", username, password.as_ref().unwrap()).as_str()); let creds = base64::encode(_buf); - headers.insert(header::AUTHORIZATION, header::HeaderValue::from_str(format!("Basic {}", creds).as_str()).unwrap()); - + headers.insert( + header::AUTHORIZATION, + header::HeaderValue::from_str(format!("Basic {}", creds).as_str()).unwrap(), + ); } - None => {}, + None => {} }; let client = reqwest::Client::builder() .user_agent(APP_USER_AGENT) .default_headers(headers) - .build().unwrap(); - Self { - client, - server - } + .build() + .unwrap(); + Self { client, server } } pub async fn list(&self, path: PathBuf) -> Result, Error> { debug!("Fetching path '{}/{}'", self.server, path.display()); @@ -77,9 +73,11 @@ impl HTTP { pub async fn read(&self, path: PathBuf, size: usize, offset: usize) -> Result, Error> { debug!("Reading path '{}/{}'", self.server, path.display()); let mut headers = header::HeaderMap::new(); - let range = format!("bytes={}-{}", offset, {offset+size}); - headers.insert(header::RANGE, header::HeaderValue::from_str(range.as_str()).unwrap()); - + let range = format!("bytes={}-{}", offset, { offset + size }); + headers.insert( + header::RANGE, + header::HeaderValue::from_str(range.as_str()).unwrap(), + ); let mut client = &self.client; let resp = client @@ -93,4 +91,3 @@ impl HTTP { Ok(resp.to_vec()) } } - diff --git a/src/main.rs b/src/main.rs index 5ef2dab..f827a97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; #[macro_use] extern crate log; use env_logger::Env; -use std::{process}; +use std::process; mod config; mod filesystem; @@ -29,7 +29,3 @@ async fn main() -> Result<(), std::io::Error> { Ok(()) } -/* -Mkdir { parent: 1, name: "123", mode: 493, umask: 18 } -Mknod { parent: 1, name: "123233", mode: 33188, rdev: 0, umask: 18 } -*/