Server: Allows loading multiple files in //

pull/186/head
Tpt 3 years ago
parent 15072f21b5
commit bb0d4fb2c4
  1. 37
      server/src/main.rs

@ -24,6 +24,7 @@ use std::fs::File;
use std::io::{BufReader, Error, ErrorKind, Read, Write}; use std::io::{BufReader, Error, ErrorKind, Read, Write};
use std::rc::Rc; use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use std::thread::{spawn, JoinHandle};
use std::time::Duration; use std::time::Duration;
use url::form_urlencoded; use url::form_urlencoded;
@ -64,6 +65,7 @@ pub fn main() -> std::io::Result<()> {
.long("file") .long("file")
.help("The file to load") .help("The file to load")
.takes_value(true) .takes_value(true)
.multiple(true)
.required(true), .required(true),
), ),
) )
@ -77,20 +79,29 @@ pub fn main() -> std::io::Result<()> {
match matches.subcommand() { match matches.subcommand() {
("load", Some(submatches)) => { ("load", Some(submatches)) => {
let file = submatches.value_of("file").unwrap(); let handles = submatches.values_of("file").unwrap().into_iter().map(|file| {
let format = file let store = store.clone();
.rsplit_once(".") let file = file.to_string();
.and_then(|(_, extension)| { spawn(move || {
DatasetFormat::from_extension(extension) let format = file
.or_else(|| GraphFormat::from_extension(extension)?.try_into().ok()) .rsplit_once(".")
.and_then(|(_, extension)| {
DatasetFormat::from_extension(extension)
.or_else(|| GraphFormat::from_extension(extension)?.try_into().ok())
})
.ok_or_else(|| {
Error::new(
ErrorKind::InvalidInput,
"The server is not able to guess the file format of {} from its extension",
)
})?;
store.bulk_load_dataset(BufReader::new(File::open(file)?), format, None)?;
Ok(())
}) })
.ok_or_else(|| { }).collect::<Vec<JoinHandle<Result<(),Error>>>>();
Error::new( for handle in handles {
ErrorKind::InvalidInput, handle.join().unwrap()?;
"The server is not able to guess the file format of {} from its extension", }
)
})?;
store.bulk_load_dataset(BufReader::new(File::open(file)?), format, None)?;
store.optimize() store.optimize()
} }
("serve", Some(submatches)) => { ("serve", Some(submatches)) => {

Loading…
Cancel
Save