Last active
September 26, 2019 02:15
-
-
Save omikuji/3e78c0e44394cc3c31def11722c53c3f to your computer and use it in GitHub Desktop.
Configuration for successful compilation with libunftp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use futures::{future, Future, Stream}; | |
use std::path::{Path, PathBuf}; | |
use std::time::SystemTime; | |
#[derive(Clone, Debug)] | |
struct SampleUser { | |
hash: String, | |
} | |
impl AsRef<SampleUser> for SampleUser { | |
fn as_ref(&self) -> &SampleUser { | |
self | |
} | |
} | |
struct SampleStorage; | |
struct SampleMetadata; | |
impl libunftp::storage::Metadata for SampleMetadata { | |
fn len(&self) -> u64 { | |
0 | |
} | |
fn is_empty(&self) -> bool { | |
self.len() == 0 | |
} | |
fn is_dir(&self) -> bool { | |
true | |
} | |
fn is_file(&self) -> bool { | |
!self.is_dir() | |
} | |
fn is_symlink(&self) -> bool { | |
false | |
} | |
fn modified(&self) -> Result<SystemTime, libunftp::storage::Error> { | |
Ok(SystemTime::now()) | |
} | |
fn gid(&self) -> u32 { | |
48 | |
} | |
fn uid(&self) -> u32 { | |
48 | |
} | |
} | |
// impl libunftp::storage::StorageBackend<SampleUser> for SampleStorage { | |
impl libunftp::storage::StorageBackend<libunftp::auth::AnonymousUser> for SampleStorage { | |
type File = std::io::Cursor<Vec<u8>>; | |
type Metadata = SampleMetadata; | |
type Error = libunftp::storage::Error; | |
fn stat<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box<dyn Future<Item = Self::Metadata, Error = Self::Error> + Send> { | |
Box::new(future::ok(Self::Metadata {})) | |
} | |
fn list<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box< | |
dyn Stream< | |
Item = libunftp::storage::Fileinfo<std::path::PathBuf, Self::Metadata>, | |
Error = Self::Error, | |
> + Send, | |
> | |
where | |
<Self as libunftp::storage::StorageBackend<libunftp::auth::AnonymousUser>>::Metadata: libunftp::storage::Metadata, | |
{ | |
let result = future::ok(vec!["a", "b", "c"]) | |
.map(|_| { | |
futures::stream::iter_ok(vec![libunftp::storage::Fileinfo { | |
path: PathBuf::from("".to_string()), | |
metadata: Self::Metadata {}, | |
}]) | |
}) | |
.flatten_stream(); | |
Box::new(result) | |
} | |
fn get<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box<dyn Future<Item = std::io::Cursor<Vec<u8>>, Error = Self::Error> + Send> { | |
Box::new(future::ok(std::io::Cursor::new(vec![0]))) | |
} | |
fn put<P: AsRef<Path>, R: tokio::prelude::AsyncRead + Send + 'static>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_bytes: R, | |
_path: P, | |
) -> Box<dyn Future<Item = u64, Error = Self::Error> + Send> { | |
Box::new(future::ok(0)) | |
} | |
fn del<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box<dyn Future<Item = (), Error = std::io::Error> + Send> { | |
Box::new(future::ok(())) | |
} | |
fn rmd<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box<dyn Future<Item = (), Error = Self::Error> + Send> { | |
Box::new(future::ok(())) | |
} | |
fn mkd<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_path: P, | |
) -> Box<dyn Future<Item = (), Error = Self::Error> + Send> { | |
Box::new(future::ok(())) | |
} | |
fn rename<P: AsRef<Path>>( | |
&self, | |
_user: &Option<libunftp::auth::AnonymousUser>, | |
_from: P, | |
_to: P, | |
) -> Box<dyn Future<Item = (), Error = Self::Error> + Send> { | |
Box::new(future::ok(())) | |
} | |
} | |
fn main() { | |
let mut rt = tokio::runtime::Runtime::new().unwrap(); | |
let server = libunftp::Server::new(Box::new(move || { SampleStorage {} })); | |
rt.spawn(server.listener("127.0.0.1:2121")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment