Fix broken pipe panic

This commit is contained in:
Matthias Beyer 2018-02-14 23:32:23 +01:00
parent 09da5cc21e
commit 632d68e0e0

View file

@ -50,6 +50,7 @@ extern crate libimagutil;
#[cfg(not(test))] #[cfg(not(test))]
extern crate libimagutil; extern crate libimagutil;
use std::io::Write;
use std::path::PathBuf; use std::path::PathBuf;
use libimagentrylink::external::ExternalLinker; use libimagentrylink::external::ExternalLinker;
@ -57,6 +58,8 @@ use libimagentrylink::internal::InternalLinker;
use libimagentrylink::internal::store_check::StoreLinkConsistentExt; use libimagentrylink::internal::store_check::StoreLinkConsistentExt;
use libimagentrylink::error::LinkError as LE; use libimagentrylink::error::LinkError as LE;
use libimagerror::trace::{MapErrTrace, trace_error}; use libimagerror::trace::{MapErrTrace, trace_error};
use libimagerror::exit::ExitUnwrap;
use libimagerror::io::ToExitCode;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagrt::setup::generate_runtime_setup; use libimagrt::setup::generate_runtime_setup;
use libimagstore::error::StoreError; use libimagstore::error::StoreError;
@ -226,7 +229,8 @@ fn list_linkings(rt: &Runtime) {
.subcommand_matches("list") .subcommand_matches("list")
.unwrap(); // safed by clap .unwrap(); // safed by clap
let list_externals = cmd.is_present("list-externals-too"); let list_externals = cmd.is_present("list-externals-too");
let mut out = ::std::io::stdout();
for entry in cmd.values_of("entries").unwrap() { // safed by clap for entry in cmd.values_of("entries").unwrap() { // safed by clap
match rt.store().get(PathBuf::from(entry)) { match rt.store().get(PathBuf::from(entry)) {
@ -240,20 +244,27 @@ fn list_linkings(rt: &Runtime) {
.ok(); .ok();
if let Some(link) = link { if let Some(link) = link {
println!("{: <3}: {}", i, link); let _ = writeln!(out, "{: <3}: {}", i, link)
.to_exit_code()
.unwrap_or_exit();
i += 1; i += 1;
} }
} }
if list_externals { if list_externals {
for link in entry.get_external_links(rt.store()).map_err_trace_exit_unwrap(1) { entry.get_external_links(rt.store())
let link = link .map_err_trace_exit_unwrap(1)
.map_err_trace_exit_unwrap(1) .enumerate()
.into_string(); .for_each(|(i, link)| {
let link = link
.map_err_trace_exit_unwrap(1)
.into_string();
println!("{: <3}: {}", i, link); let _ = writeln!(out, "{: <3}: {}", i, link)
i += 1; .to_exit_code()
} .unwrap_or_exit();
})
} }
}, },
Ok(None) => warn!("Not found: {}", entry), Ok(None) => warn!("Not found: {}", entry),