This commit is contained in:
AB
2020-06-05 14:31:29 +03:00
parent 28c6fa93b6
commit bf8b2e59b7
4 changed files with 33 additions and 3 deletions

16
Cargo.lock generated
View File

@ -184,6 +184,12 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3" checksum = "4358a9e11b9a09cf52383b451b49a169e8d797b68aa02301ff586d70d9661ea3"
[[package]]
name = "either"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.23" version = "0.8.23"
@ -256,6 +262,7 @@ dependencies = [
"env_logger", "env_logger",
"futures", "futures",
"futures-intrusive", "futures-intrusive",
"itertools",
"libc", "libc",
"log", "log",
"percent-encoding", "percent-encoding",
@ -525,6 +532,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "0.4.5" version = "0.4.5"

View File

@ -33,6 +33,7 @@ size_format = "1.0"
base64 = "0.12" base64 = "0.12"
ctrlc = "3.1" ctrlc = "3.1"
config = "0.9" config = "0.9"
itertools = "*"
[dev-dependencies.tokio] [dev-dependencies.tokio]
version = "0.2" version = "0.2"

View File

@ -66,14 +66,15 @@ impl HTTP {
.await? .await?
.json::<Vec<RemoteEntry>>() .json::<Vec<RemoteEntry>>()
.await?; .await?;
info!("Found {} entries into '{}'", resp.len(), path.display()); debug!("Found {} entries into '{}'", resp.len(), path.display());
Ok(resp) Ok(resp)
} }
pub async fn read(&self, path: PathBuf, size: usize, offset: usize) -> Result<Vec<u8>, Error> { pub async fn read(&self, path: PathBuf, size: usize, offset: usize) -> Result<Vec<u8>, Error> {
debug!("Reading path '{}/{}'", self.server, path.display()); debug!("Reading path '{}/{}'", self.server, path.display());
let mut headers = header::HeaderMap::new(); let mut headers = header::HeaderMap::new();
let range = format!("bytes={}-{}", offset, { offset + size }); let range = format!("bytes={}-{}", offset, { offset + size - 1 });
info!("range = {:?}", range);
headers.insert( headers.insert(
header::RANGE, header::RANGE,
header::HeaderValue::from_str(range.as_str()).unwrap(), header::HeaderValue::from_str(range.as_str()).unwrap(),

View File

@ -3,10 +3,12 @@ use std::path::PathBuf;
extern crate log; extern crate log;
use env_logger::Env; use env_logger::Env;
use std::process; use std::process;
use std::ffi::OsStr;
mod config; mod config;
mod filesystem; mod filesystem;
mod http; mod http;
use itertools::Itertools;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), std::io::Error> { async fn main() -> Result<(), std::io::Error> {
@ -22,10 +24,20 @@ async fn main() -> Result<(), std::io::Error> {
error!("The mountpoint must be a directory"); error!("The mountpoint must be a directory");
process::exit(0x0004); process::exit(0x0004);
} }
let options = [
"ro",
"fsname=furumi-http",
// "sync_read",
"auto_unmount",
"allow_other",
].iter().join(",");
let memfs = filesystem::MemFS::new(&cfg); let memfs = filesystem::MemFS::new(&cfg);
memfs.fetch_remote(PathBuf::from("/"), 1).await; memfs.fetch_remote(PathBuf::from("/"), 1).await;
polyfuse_tokio::mount(memfs, mountpoint, &[]).await?; polyfuse_tokio::mount(memfs, mountpoint, &[
"-o".as_ref(),
options.as_ref(),
],).await?;
Ok(()) Ok(())
} }