This commit is contained in:
AB
2020-06-05 02:29:07 +03:00
parent 6e6bab7e55
commit 28c6fa93b6
3 changed files with 26 additions and 32 deletions

View File

@ -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<impl Reply + Debug> {
let full_path_mutex = self.f_ino_map.lock().await;
let mut counter = 0;
let full_path = loop {

View File

@ -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<String>, password: Option<String>, ) -> Self {
pub fn new(server: String, username: Option<String>, password: Option<String>) -> 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<Vec<RemoteEntry>, 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<Vec<u8>, 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())
}
}

View File

@ -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 }
*/