diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-13 13:44:23 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-13 13:44:23 +0200 |
commit | 1aea20cbc7f919fcc42d7b67c2ae609d6c33a0d9 (patch) | |
tree | 55d5e3a0efaad06ac64e5e141437a4ea9eec563c | |
parent | 1891e3c8344a4724e3b667a458bf4e9ebd64ded2 (diff) | |
download | lr-1aea20cbc7f919fcc42d7b67c2ae609d6c33a0d9.tar.gz lr-1aea20cbc7f919fcc42d7b67c2ae609d6c33a0d9.tar.xz lr-1aea20cbc7f919fcc42d7b67c2ae609d6c33a0d9.zip |
lr: print errors and return status 1 when a toplevel argument cannot be stat'ed
-rw-r--r-- | lr.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/lr.c b/lr.c index e36cb03..fbf0f8a 100644 --- a/lr.c +++ b/lr.c @@ -95,6 +95,7 @@ static int prune; static size_t prefixl; static char input_delim = '\n'; static int current_color; +static int status; static char default_ordering[] = "n"; static char default_format[] = "%p\\n"; @@ -1776,10 +1777,18 @@ recurse(char *path, struct history *h) int resolve = Lflag || (Hflag && !h); if (resolve ? stat(fpath, &st) : lstat(fpath, &st) < 0) { - if (resolve && errno == ENOENT && !lstat(fpath, &st)) - ; - else if (errno != EACCES) + if (resolve && errno == ENOENT && !lstat(fpath, &st)) { + /* ignore */ + } else if (!h) { + /* warn for toplevel arguments */ + fprintf(stderr, "lr: cannot %sstat '%s': %s\n", + resolve ? "" : "l", + fpath, strerror(errno)); + status = 1; return -1; + } else if (errno != EACCES) { + return -1; + } } if (xflag && h && st.st_dev != h->dev) @@ -1925,6 +1934,7 @@ main(int argc, char *argv[]) ordering = default_ordering; argv0 = argv[0]; now = time(0); + status = 0; while ((c = getopt(argc, argv, "01AC:DFGHLQST:Udf:lho:st:x")) != -1) switch(c) { @@ -1995,5 +2005,5 @@ main(int argc, char *argv[]) if (!Uflag) twalk(root, print); - return 0; + return status; } |