From 2602a97892eabfed05280832b4bd995d22b91283 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 17 Dec 2018 22:23:56 -0400 Subject: [PATCH] Using i64 for filesize --- src/bin/copy.rs | 18 +++++++++--------- src/bin/meta_data.rs | 6 ++---- src/lib.rs | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/bin/copy.rs b/src/bin/copy.rs index 9f2cd3b..530675f 100644 --- a/src/bin/copy.rs +++ b/src/bin/copy.rs @@ -1,12 +1,11 @@ extern crate a03; extern crate serde; extern crate serde_json; -#[macro_use] extern crate serde_derive; use a03::*; use std::net::{TcpStream, Shutdown}; -use std::io::{Write, Read}; +use std::io::Write; use std::fs::File; use std::fs; @@ -19,9 +18,9 @@ fn main() { packet_type = PacketType::RequestWrite; let file = fs::read(&args.filename).unwrap(); let size = file.len(); - println!("Requesting Write of {}", args.filepath); + println!("Sending file of size {}", size); json = Some(serde_json::to_string( - &AddFile { name: args.filepath.clone(), size: size as u32 }).unwrap()) + &AddFile { name: args.filepath.clone(), size: size as u64 }).unwrap()) } else { packet_type = PacketType::RequestRead; println!("Requesting Read of {}", args.filepath); @@ -68,7 +67,8 @@ fn send_file_to_data_nodes( index: node.chunk_index, filename: filename.clone(), }; - let packet = serde_json::to_writer( + println!("Sending"); + serde_json::to_writer( &mut stream, &Packet { p_type: PacketType::PutFile, @@ -76,9 +76,9 @@ fn send_file_to_data_nodes( data: Some(chunks[node.chunk_index as usize].to_vec()), // data: None, }).unwrap(); - stream.flush().unwrap(); - stream.shutdown(Shutdown::Write).unwrap(); } +// stream.flush().unwrap(); +// stream.shutdown(Shutdown::Write).unwrap(); } fn get_file_from_data_nodes( @@ -95,7 +95,7 @@ fn get_file_from_data_nodes( }; let endpoint = format!("{}:{}", node.ip, node.port); let mut stream = TcpStream::connect(endpoint).unwrap(); - let packet = serde_json::to_writer( + serde_json::to_writer( &stream, &Packet { p_type: PacketType::GetFile, @@ -135,7 +135,7 @@ pub struct CliArgs { } pub fn get_cli_args() -> CliArgs { - let mut args: Vec = std::env::args().skip(1).collect(); + let args: Vec = std::env::args().skip(1).collect(); if args.len() < 2 { panic!("Requires 2 arguments; IP:PORT:FILEPATH and a Local filename/filepath") } diff --git a/src/bin/meta_data.rs b/src/bin/meta_data.rs index b1d685f..f891ca3 100644 --- a/src/bin/meta_data.rs +++ b/src/bin/meta_data.rs @@ -75,7 +75,7 @@ fn request_read(stream: &mut TcpStream, conn: &Connection, message: &str) { fn request_write(stream: &mut TcpStream, conn: &Connection, message: &str) { let file: AddFile = serde_json::from_str(message).unwrap(); - let file_already_exists = add_file(&conn, &file.name, file.size as i32); + let file_already_exists = add_file(&conn, &file.name, file.size as i64); if file_already_exists { match serde_json::to_writer( stream, @@ -90,8 +90,6 @@ fn request_write(stream: &mut TcpStream, conn: &Connection, message: &str) { return; } let file_info = get_file_info(&conn, &file.name).unwrap(); -// let file_info = INode { id: 1, name: file.name, size: file.size }; -// println!("{:?}", file_info); let mut blocks: Vec = Vec::new(); let mut nodes: Vec = Vec::new(); let dnodes = get_data_nodes(&conn); @@ -201,7 +199,7 @@ fn get_data_nodes(conn: &Connection) -> Vec { nodes } -fn add_file(conn: &Connection, fname: &String, fsize: i32) -> bool { +fn add_file(conn: &Connection, fname: &String, fsize: i64) -> bool { let file_exists = conn.query_row( "SELECT fid FROM inode WHERE fname = ?1", &[&fname as &ToSql], diff --git a/src/lib.rs b/src/lib.rs index 5965e4c..bbf4b99 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,7 +46,7 @@ pub struct NodeRegistration { #[derive(Serialize, Deserialize, Debug)] pub struct AddFile { pub name: String, - pub size: u32 + pub size: u64, } #[derive(Serialize, Deserialize, Debug)]