INNER CODE UNIT · Rust
view_directory
atanunq/viu · src/app.rs:89
fn view_directory(conf: &Config, dirname: &str, (tx, rx): TxRx) -> ViuResult {
for dir_entry_result in fs::read_dir(dirname)? {
//check if Ctrl-C has been received. If yes, stop iterating
if rx.try_recv().is_ok() {
return tx
.send(true)
.map_err(|_| Error::other("Could not send signal to clean up.").into());
};
let dir_entry = dir_entry_result?;
//check if the given file is a directory
if let Some(path_name) = dir_entry.path().to_str() {
//if -r is passed, continue down
if conf.recursive && dir_entry.metadata()?.is_dir() {
view_directory(conf, path_name, (tx, rx))?;
}
//if it is a regular file, viu it, but do not exit on error
else {