aboutsummaryrefslogtreecommitdiffstats
path: root/src/common.rs
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-02 21:02:11 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-02 21:02:11 -0400
commit5ca100e6f085bad332df16580e6b292b24e01317 (patch)
tree2b5d09097fabe8ba1c8823ed7003c6a872cf31a6 /src/common.rs
parent220e7ccb16311a390504a10f42ba1a1290b0630b (diff)
downloaducp-5ca100e6f085bad332df16580e6b292b24e01317.tar.gz
ucp-5ca100e6f085bad332df16580e6b292b24e01317.zip
start cleaning up error conditions
Diffstat (limited to 'src/common.rs')
-rw-r--r--src/common.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/common.rs b/src/common.rs
index bf3910e..77b28ce 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -9,7 +9,7 @@ use std::io::{Read, Write, BufRead, BufReader};
use std::process::exit;
use std::net;
-pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) {
+pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) -> Result<(), String> {
println!("SOURCE FILE: {}", file_path);
if recursive { unimplemented!(); }
let mut f = File::open(file_path).unwrap();
@@ -54,6 +54,7 @@ pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive:
},
_ => { panic!("Unexpected status char!") },
};
+ Ok(())
}
fn raw_read_line<S: Read + Write>(stream: &mut S) -> io::Result<String> {
@@ -72,7 +73,7 @@ fn raw_read_line<S: Read + Write>(stream: &mut S) -> io::Result<String> {
// TODO: it would be nice to be able to do BufReader/BufWriter on stream. This would require
// implementations of Read and Write on immutable references to stream (a la TcpStream, File, et
// al)
-pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) {
+pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) -> Result<(), String> {
println!("SINK FILE: {}", file_path);
if recursive { unimplemented!(); }
let mut f = File::create(file_path).unwrap();
@@ -115,4 +116,5 @@ pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: b
f.sync_all().unwrap();
// f.close(); XXX: closes automatically?
stream.write(&[0]).unwrap();
+ Ok(())
}