Commit fe5ff88b authored by Xiaowu Zhang's avatar Xiaowu Zhang

write to file

parent 46de40d4
use anyhow::Result; use anyhow::Result;
use blocking::multipart;
use clap::{App, Arg}; use clap::{App, Arg};
use multipart::Part;
use rayon::prelude::*; use rayon::prelude::*;
use reqwest::{ use reqwest::{
blocking::{self, Client}, blocking::{self, Client},
...@@ -217,17 +215,6 @@ fn construct_fs_tree( ...@@ -217,17 +215,6 @@ fn construct_fs_tree(
Ok(cur_tree) Ok(cur_tree)
} }
fn upload_to_erp5<R: Read + Send + 'static>(
reader: R,
size: u64,
base_url: &str,
username: &str,
password: &str,
reference: &str,
) -> Result<()> {
Part::reader_with_length(reader, size).file_name(format!("/var/log/metadata_collect.log"));
Ok(())
}
fn main() -> Result<()> { fn main() -> Result<()> {
let m = App::new("metadata-collect-agent") let m = App::new("metadata-collect-agent")
...@@ -236,22 +223,6 @@ fn main() -> Result<()> { ...@@ -236,22 +223,6 @@ fn main() -> Result<()> {
.required(true) .required(true)
.takes_value(true) .takes_value(true)
.multiple(false), .multiple(false),
Arg::with_name("erp5-user")
.takes_value(true)
.multiple(false)
.required(true),
Arg::with_name("erp5-pass")
.takes_value(true)
.multiple(false)
.required(true),
Arg::with_name("erp5-file-reference")
.takes_value(true)
.multiple(false)
.required(true),
Arg::with_name("erp5-base-url")
.takes_value(true)
.multiple(false)
.required(true),
Arg::with_name("ignored-dirs") Arg::with_name("ignored-dirs")
.takes_value(true) .takes_value(true)
.multiple(true) .multiple(true)
...@@ -283,21 +254,10 @@ fn main() -> Result<()> { ...@@ -283,21 +254,10 @@ fn main() -> Result<()> {
&ignored_dirs, &ignored_dirs,
)?, )?,
}; };
let packed = serde_json::to_string(&snapshot)?;
let packed = serde_json::to_vec(&snapshot)?; for s in packed.split(":{"){
let packed_size = packed.len() as u64; file.write_all((s.to_owned()+"\n").as_bytes());
}
upload_to_erp5(
Cursor::new(packed),
packed_size,
m.value_of("erp5-base-url").unwrap(),
m.value_of("erp5-user").unwrap(),
m.value_of("erp5-pass").unwrap(),
m.value_of("erp5-file-reference").unwrap(),
)?;
writeln!(file, "[200202: end]");
writeln!(file, "[2020222: end]");
let _result = child.wait().unwrap(); let _result = child.wait().unwrap();
Ok(()) Ok(())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment