refactor: clippy
This commit is contained in:
parent
a3ccc63d37
commit
1c14a81e18
1 changed files with 17 additions and 26 deletions
43
src/main.rs
43
src/main.rs
|
@ -17,7 +17,7 @@ struct UserEnvironment {
|
||||||
debug: bool,
|
debug: bool,
|
||||||
}
|
}
|
||||||
impl UserEnvironment {
|
impl UserEnvironment {
|
||||||
fn user_environment() -> UserEnvironment {
|
fn new() -> UserEnvironment {
|
||||||
UserEnvironment {
|
UserEnvironment {
|
||||||
ip: "127.0.0.1".parse().unwrap(),
|
ip: "127.0.0.1".parse().unwrap(),
|
||||||
port: 2121,
|
port: 2121,
|
||||||
|
@ -39,7 +39,7 @@ struct FileInfo {
|
||||||
progress: u8,
|
progress: u8,
|
||||||
}
|
}
|
||||||
impl FileInfo {
|
impl FileInfo {
|
||||||
fn file_info() -> FileInfo {
|
fn new() -> FileInfo {
|
||||||
FileInfo {
|
FileInfo {
|
||||||
file: None,
|
file: None,
|
||||||
location: None,
|
location: None,
|
||||||
|
@ -63,12 +63,11 @@ impl FileInfo {
|
||||||
if Metadata::is_symlink(metadata) {
|
if Metadata::is_symlink(metadata) {
|
||||||
//Unix-Windows Problem
|
//Unix-Windows Problem
|
||||||
println!("\n\tError: Symlink Transfers've not Supported yet\n");
|
println!("\n\tError: Symlink Transfers've not Supported yet\n");
|
||||||
return;
|
|
||||||
//self.open_file(debug_mode);
|
//self.open_file(debug_mode);
|
||||||
//self.send_file(stream, &(100 as u8),debug_mode);
|
//self.send_file(stream, &(100 as u8),debug_mode);
|
||||||
} else if Metadata::is_file(metadata) {
|
} else if Metadata::is_file(metadata) {
|
||||||
self.open_file(debug_mode);
|
self.open_file(debug_mode);
|
||||||
self.send_file(stream, &(101 as u8), debug_mode);
|
self.send_file(stream, &(101_u8), debug_mode);
|
||||||
} else if Metadata::is_dir(metadata) {
|
} else if Metadata::is_dir(metadata) {
|
||||||
//path recognition and creation on the other side
|
//path recognition and creation on the other side
|
||||||
//std:path
|
//std:path
|
||||||
|
@ -121,7 +120,7 @@ impl FileInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match fs::metadata(&self.location.as_ref().unwrap()) {
|
match fs::metadata(self.location.as_ref().unwrap()) {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
self.metadata = Some(metadata);
|
self.metadata = Some(metadata);
|
||||||
if *debug_mode {
|
if *debug_mode {
|
||||||
|
@ -156,7 +155,6 @@ impl FileInfo {
|
||||||
self.location.as_ref().unwrap(),
|
self.location.as_ref().unwrap(),
|
||||||
err_val
|
err_val
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,16 +218,12 @@ impl FileInfo {
|
||||||
if *debug_mode {
|
if *debug_mode {
|
||||||
println!("Read Data = {:#?}", buffer);
|
println!("Read Data = {:#?}", buffer);
|
||||||
}
|
}
|
||||||
self.send_exact(&mut buffer, stream, debug_mode);
|
self.send_exact(&buffer, stream, debug_mode);
|
||||||
self.show_progress(iteration, total_iteration);
|
self.show_progress(iteration, total_iteration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn callback_validation(&mut self, stream: &mut TcpStream, data: &String, debug_mode: &bool) {
|
fn callback_validation(&mut self, stream: &mut TcpStream, data: &String, debug_mode: &bool) {
|
||||||
self.send_exact(
|
self.send_exact(format!("{}{}", data, "\n").as_bytes(), stream, debug_mode);
|
||||||
String::from(data.clone() + "\n").as_bytes(),
|
|
||||||
stream,
|
|
||||||
debug_mode,
|
|
||||||
);
|
|
||||||
match self.recv_until(stream, '\n', debug_mode) {
|
match self.recv_until(stream, '\n', debug_mode) {
|
||||||
Some(callback_callback) => {
|
Some(callback_callback) => {
|
||||||
if callback_callback == data.to_string().as_bytes().to_vec() {
|
if callback_callback == data.to_string().as_bytes().to_vec() {
|
||||||
|
@ -338,7 +332,7 @@ impl FileInfo {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(buffer);
|
Some(buffer)
|
||||||
}
|
}
|
||||||
fn forge_file(&mut self, location: String, debug_mode: &bool) {
|
fn forge_file(&mut self, location: String, debug_mode: &bool) {
|
||||||
//dont forget
|
//dont forget
|
||||||
|
@ -390,7 +384,7 @@ impl FileInfo {
|
||||||
}
|
}
|
||||||
let data = String::from_utf8(callback.clone()).unwrap();
|
let data = String::from_utf8(callback.clone()).unwrap();
|
||||||
callback.push(b'\n');
|
callback.push(b'\n');
|
||||||
self.send_exact(&callback.as_slice(), stream, debug_mode);
|
self.send_exact(callback.as_slice(), stream, debug_mode);
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
@ -479,7 +473,7 @@ impl FileInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.open_file(debug_mode);
|
self.open_file(debug_mode);
|
||||||
let mut iteration: u64 = (&self.size_total / BUFFER_SIZE) + 1;
|
let mut iteration: u64 = (self.size_total / BUFFER_SIZE) + 1;
|
||||||
let total_iteration = iteration;
|
let total_iteration = iteration;
|
||||||
self.show_info(&iteration, debug_mode);
|
self.show_info(&iteration, debug_mode);
|
||||||
while iteration != 0 {
|
while iteration != 0 {
|
||||||
|
@ -490,7 +484,7 @@ impl FileInfo {
|
||||||
self.save_exact(&buffer, debug_mode);
|
self.save_exact(&buffer, debug_mode);
|
||||||
} else {
|
} else {
|
||||||
self.save_exact(
|
self.save_exact(
|
||||||
&buffer[..(&self.size_total % BUFFER_SIZE) as usize],
|
&buffer[..(self.size_total % BUFFER_SIZE) as usize],
|
||||||
debug_mode,
|
debug_mode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -507,7 +501,7 @@ impl FileInfo {
|
||||||
fn show_progress(&mut self, iteration: u64, total_iteration: u64) {
|
fn show_progress(&mut self, iteration: u64, total_iteration: u64) {
|
||||||
if iteration % 10 == 0 {
|
if iteration % 10 == 0 {
|
||||||
let progress: u8 =
|
let progress: u8 =
|
||||||
100 as u8 - ((iteration as f64 / total_iteration as f64) * 100 as f64) as u8;
|
100_u8 - ((iteration as f64 / total_iteration as f64) * 100_f64) as u8;
|
||||||
if progress != self.progress {
|
if progress != self.progress {
|
||||||
self.progress = progress;
|
self.progress = progress;
|
||||||
println!("%{}", self.progress);
|
println!("%{}", self.progress);
|
||||||
|
@ -601,7 +595,7 @@ fn send_or_receive(
|
||||||
match user_environment.send {
|
match user_environment.send {
|
||||||
true => {
|
true => {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
FileInfo::reading_operations(file_info, stream, &debug_mode);
|
FileInfo::reading_operations(file_info, stream, debug_mode);
|
||||||
let finish_time = Instant::now();
|
let finish_time = Instant::now();
|
||||||
println!("Done: Transfer");
|
println!("Done: Transfer");
|
||||||
println!(
|
println!(
|
||||||
|
@ -611,7 +605,7 @@ fn send_or_receive(
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
FileInfo::writing_operations(file_info, stream, &debug_mode);
|
FileInfo::writing_operations(file_info, stream, debug_mode);
|
||||||
let finish_time = Instant::now();
|
let finish_time = Instant::now();
|
||||||
println!("Done: Transfer");
|
println!("Done: Transfer");
|
||||||
println!(
|
println!(
|
||||||
|
@ -693,16 +687,13 @@ fn main() {
|
||||||
//First we should check folder structure and validation then make connection.
|
//First we should check folder structure and validation then make connection.
|
||||||
//Until's can be deprecated, 100k byte should be enough for eveything.(Security)
|
//Until's can be deprecated, 100k byte should be enough for eveything.(Security)
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
let mut file_info: FileInfo = FileInfo::file_info();
|
let mut file_info: FileInfo = FileInfo::new();
|
||||||
let user_environment: UserEnvironment;
|
let user_environment: UserEnvironment = match take_args(UserEnvironment::new()) {
|
||||||
match take_args(UserEnvironment::user_environment()) {
|
Some(usr_env) => usr_env,
|
||||||
Some(usr_env) => {
|
|
||||||
user_environment = usr_env;
|
|
||||||
}
|
|
||||||
None => {
|
None => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
file_info.pass_user_environment(&user_environment);
|
file_info.pass_user_environment(&user_environment);
|
||||||
match user_environment.server {
|
match user_environment.server {
|
||||||
true => {
|
true => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue