Skip to content

Commit 86ad527

Browse files
authored
Merge pull request eza-community#319 from eza-community/cafk-exit-13
fix(file): exit 13 on os error 13
2 parents 4c04ce1 + e7a50d3 commit 86ad527

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/fs/dir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl Dir {
4242
.map(|result| result.map(|entry| entry.path()))
4343
.collect::<Result<_, _>>()?;
4444

45+
info!("Read directory success {:?}", &path);
4546
Ok(Self { contents, path })
4647
}
4748

src/fs/file.rs

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl<'dir> File<'dir> {
204204
/// Returns an IO error upon failure, but this shouldn’t be used to check
205205
/// if a `File` is a directory or not! For that, just use `is_directory()`.
206206
pub fn to_dir(&self) -> io::Result<Dir> {
207+
trace!("to_dir: reading dir");
207208
Dir::read_dir(self.path.clone())
208209
}
209210

@@ -531,6 +532,7 @@ impl<'dir> File<'dir> {
531532
/// but as mentioned in the size function comment above, different filesystems
532533
/// make it difficult to get any info about a dir by it's size, so this may be it.
533534
fn is_empty_directory(&self) -> bool {
535+
trace!("is_empty_directory: reading dir");
534536
match Dir::read_dir(self.path.clone()) {
535537
// . & .. are skipped, if the returned iterator has .next(), it's not empty
536538
Ok(has_files) => has_files.files(super::DotFilter::Dotfiles, None, false, false).next().is_none(),

src/main.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::env;
2727
use std::ffi::{OsStr, OsString};
2828
use std::io::{self, Write, ErrorKind};
2929
use std::path::{Component, PathBuf};
30+
use std::process::exit;
3031

3132
use ansiterm::{ANSIStrings, Style};
3233

@@ -87,8 +88,6 @@ lazy_static! {
8788
}
8889

8990
fn main() {
90-
use std::process::exit;
91-
9291
#[cfg(unix)]
9392
unsafe {
9493
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
@@ -118,8 +117,11 @@ fn main() {
118117
let theme = options.theme.to_theme(terminal_size::terminal_size().is_some());
119118
let exa = Exa { options, writer, input_paths, theme, console_width, git };
120119

120+
121+
info!("matching on exa.run");
121122
match exa.run() {
122123
Ok(exit_status) => {
124+
trace!("exa.run: exit Ok(exit_status)");
123125
exit(exit_status);
124126
}
125127

@@ -130,6 +132,7 @@ fn main() {
130132

131133
Err(e) => {
132134
eprintln!("{e}");
135+
trace!("exa.run: exit RUNTIME_ERROR");
133136
exit(exits::RUNTIME_ERROR);
134137
}
135138
}
@@ -225,8 +228,13 @@ impl<'args> Exa<'args> {
225228

226229
Ok(f) => {
227230
if f.points_to_directory() && ! self.options.dir_action.treat_dirs_as_files() {
231+
trace!("matching on to_dir");
228232
match f.to_dir() {
229233
Ok(d) => dirs.push(d),
234+
Err(e) if e.kind() == ErrorKind::PermissionDenied => {
235+
warn!("Permission Denied: {e}");
236+
exit(exits::PERMISSION_DENIED);
237+
},
230238
Err(e) => writeln!(io::stderr(), "{file_path:?}: {e}")?,
231239
}
232240
}
@@ -378,4 +386,7 @@ mod exits {
378386

379387
/// Exit code for when the command-line options are invalid.
380388
pub const OPTIONS_ERROR: i32 = 3;
389+
390+
/// Exit code for missing file permissions
391+
pub const PERMISSION_DENIED: i32 = 13;
381392
}

src/output/details.rs

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ use std::vec::IntoIter as VecIntoIter;
6868
use ansiterm::Style;
6969
use scoped_threadpool::Pool;
7070

71+
use log::*;
72+
7173
use crate::fs::{Dir, File};
7274
use crate::fs::dir_action::RecurseOptions;
7375
use crate::fs::feature::git::GitCache;
@@ -261,6 +263,7 @@ impl<'a> Render<'a> {
261263
let mut dir = None;
262264
if let Some(r) = self.recurse {
263265
if file.is_directory() && r.tree && ! r.is_too_deep(depth.0) {
266+
trace!("matching on to_dir");
264267
match file.to_dir() {
265268
Ok(d) => {
266269
dir = Some(d);

0 commit comments

Comments
 (0)