From d2711492895599c031ce97ad8238026a3c40f8b0 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:04:15 +0800 Subject: [PATCH] tail: warn for directory args * The -f mode of tail calls tail_f(), passing file & directory arguments as separate params * By default handle_args() loops over Files list, not Dirs list, so directory arguments were silently ignored * Make the default case follow GNU tail and print a warning for each directory argument, and exit with error code --- bin/tail | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/tail b/bin/tail index 692e73f2..6318caec 100755 --- a/bin/tail +++ b/bin/tail @@ -380,8 +380,13 @@ sub handle_args($$$) my @dirs; for my $f (@$files_) { - if(-d $f) { - push @dirs, $f; + if (-d $f) { + if ($opt_f) { + push @dirs, $f; + } else { + warn "$me: '$f' is a directory\n"; + $rc = EX_FAILURE; + } } else { push @files, $f; }