diff --git a/less-436-empty-lessopen-pipe.patch b/less-436-empty-lessopen-pipe.patch new file mode 100644 index 0000000..41311d4 --- /dev/null +++ b/less-436-empty-lessopen-pipe.patch @@ -0,0 +1,39 @@ +--- less-436/filename.c 2009-07-06 22:52:23.000000000 +0200 ++++ less-436_vvitek/filename.c 2010-12-08 16:01:41.269695932 +0100 +@@ -879,17 +879,32 @@ open_altfile(filename, pf, pfd) + */ + f = fileno(fd); + SET_BINARY(f); ++ *pfd = (void *) fd; ++ *pf = f; + if (read(f, &c, 1) != 1) + { + /* +- * Pipe is empty. This means there is no alt file. ++ * Error or pipe is empty. Close it and ++ * check exit status of the pipe process. + */ +- pclose(fd); ++ if (pclose(fd) == 0) { ++ /* ++ * Exit status was zero, so the EOF was correct ++ * empty output. Let the program open /dev/null ++ * instead, as the pipe is already closed. ++ * Set force_open to omit bad_file() check ++ * failure, as it is special 'c' pseudo-device. ++ */ ++ *pf = 0; ++ *pfd = NULL; ++ force_open = 1; ++ return (save("/dev/null")); ++ } ++ *pf = 0; ++ *pfd = NULL; + return (NULL); + } + ch_ungetchar(c); +- *pfd = (void *) fd; +- *pf = f; + return (save("-")); + } + #endif diff --git a/less.spec b/less.spec index 5251747..81209f6 100644 --- a/less.spec +++ b/less.spec @@ -12,6 +12,7 @@ Patch1: less-406-Foption.patch Patch4: less-394-time.patch Patch5: less-418-fsync.patch Patch6: less-436-manpage.patch +Patch7: less-436-empty-lessopen-pipe.patch URL: http://www.greenwoodsoftware.com/less/ Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: ncurses-devel @@ -34,6 +35,7 @@ files, and you'll use it frequently. %patch4 -p1 -b .time %patch5 -p1 -b .fsync %patch6 -p1 -b .manpage +%patch7 -p1 -b .empty-lessopen-pipe autoreconf @@ -65,6 +67,10 @@ ls -la $RPM_BUILD_ROOT/etc/profile.d rm -rf $RPM_BUILD_ROOT %changelog +* Tue Dec 21 2010 Vojtech Vitek (V-Teq) - 436-7 +- Fix for valid empty LESSOPEN pipe output + Resolves: #579251, #615303 + * Wed Jan 20 2010 Nikola Pajkovsky - 436-6 - RFE: lesspipe.sh could use a support for *.xz file diff --git a/lesspipe.sh b/lesspipe.sh index 3d67505..cfb710a 100755 --- a/lesspipe.sh +++ b/lesspipe.sh @@ -2,23 +2,30 @@ # # To use this filter with less, define LESSOPEN: # export LESSOPEN="|/usr/bin/lesspipe.sh %s" +# +# Script should return zero on success. This is important in case +# of empty output of any decompressor when the output pipe produces +# just EOF (eg. while uncompressing gzipped empty file). lesspipe() { case "$1" in *.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.man.gz|*.[1-9].xz|*.[1-9]x.xz|*.man.xz) case "$1" in - *.gz) DECOMPRESSOR="gunzip -c" ;; - *.bz2) DECOMPRESSOR="bunzip2 -c" ;; - *) DECOMPRESSOR="cat" ;; + *.gz) DECOMPRESSOR="gzip -dc" ;; + *.bz2) DECOMPRESSOR="bzip2 -dc" ;; esac - if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then - if echo "$1" | grep -q ^/; then #absolute path - man -- "$1" | cat -s - else - man -- "./$1" | cat -s - fi + if [ ! -z $DECOMPRESSOR ] ; then + if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then + if echo "$1" | grep -q ^/; then #absolute path + man -- "$1" | cat -s + else + man -- "./$1" | cat -s + fi + else + $DECOMPRESSOR -- "$1" + fi else - $DECOMPRESSOR -- "$1" + exit 1 fi ;; *.tar) tar tvvf "$1" ;; *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;; @@ -32,28 +39,27 @@ lesspipe() { *.rpm) rpm -qpivl --changelog -- "$1" ;; *.cpi|*.cpio) cpio -itv < "$1" ;; *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif) - if [ -x /usr/bin/identify ]; then - identify "$1" - elif [ -x /usr/bin/gm ]; then - gm identify "$1" - else - echo "No identify available" - echo "Install ImageMagick or GraphicsMagick to browse images" - fi ;; + if [ -x /usr/bin/identify ]; then + identify "$1" + elif [ -x /usr/bin/gm ]; then + gm identify "$1" + else + echo "No identify available" + echo "Install ImageMagick or GraphicsMagick to browse images" + fi ;; *) - case "$1" in - *.gz) DECOMPRESSOR="gunzip -c" ;; - *.bz2) DECOMPRESSOR="bunzip2 -c" ;; - *.xz) DECOMPRESSOR="unxz -c" ;; - esac - if [ ! -z $DECOMPRESSOR ] ; then - $DECOMPRESSOR -- "$1" ; - fi + exit 1 esac + exit $? } +if [ ! -e "$1" ] ; then + exit 1 +fi + if [ -d "$1" ] ; then /bin/ls -alF -- "$1" + exit $? else lesspipe "$1" 2> /dev/null fi