Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 340037 - sys-apps/file-5.0{3,4} returns success on error
Summary: sys-apps/file-5.0{3,4} returns success on error
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: Normal minor (vote)
Assignee: Gentoo Linux bug wranglers
Depends on:
Reported: 2010-10-07 08:23 UTC by Evert
Modified: 2010-10-09 14:50 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Evert 2010-10-07 08:23:06 UTC
file returns 0 when file does not exists.

$ file nfsdjsld
nfsdjsld: cannot open `nfsdjsld' (No such file or directory)
$ echo $?
$ man file
     file returns 0 on success, and non-zero on error.

Reproducible: Always

Steps to Reproduce:
1. file nfsdjsld
2. echo $?
3. man file

Actual Results:  
file return code $? = 0

Expected Results:  
file return code $? = 1 (just like cat etc.)

$ emerge --info
Portage (default/linux/x86/10.0/desktop/gnome, gcc-4.4.3, glibc-2.11.2-r0, i686)
System uname: Linux-
Timestamp of tree: Thu, 07 Oct 2010 00:45:01 +0000
app-shells/bash:     4.1_p7
dev-java/java-config: 2.1.11
dev-lang/python:     2.6.5-r3, 3.1.2-r4
dev-util/cmake:      2.8.1-r2
sys-apps/baselayout: 1.12.13
sys-apps/sandbox:    2.3-r1
sys-devel/autoconf:  2.13, 2.65-r1
sys-devel/automake:  1.9.6-r3, 1.10.3, 1.11.1
sys-devel/binutils:  2.20.1-r1
sys-devel/gcc:       4.4.3-r2
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.10
sys-devel/make:      3.81-r2
virtual/os-headers:  2.6.30-r1
CFLAGS="-O2 -march=native -pipe"
CONFIG_PROTECT="/etc /usr/share/X11/xkb /var/bind /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=native -pipe"
FEATURES="assume-digests distlocks fixpackages metadata-transfer news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en en_US en_GB nl de"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
USE="3dnow 3dnowext X a52 aac acl acpi alsa ao apache2 apm berkdb bluetooth branding bzip2 cairo cdr cli consolekit cpudetection cracklib crypt cups cxx dbus dri dts dvb dvd dvdr dvdread eds emboss encode esd evo exif fam ffmpeg firefox flac fortran gdbm gdu gif gimp gmp gnome gnome-keyring gpm gstreamer gtk hal iconv icu imlib ipv6 java jpeg latex lcms ldap libnotify libsamplerate mad mikmod mmx mng modules mozilla mp3 mp4 mpeg mplayer mudflap nautilus ncurses nls nptl nptlonly nsplugin ogg opengl openmp pam pango pcre pdf perl png policykit ppds pppd python qt3support qt4 quicktime readline reflection samba sdl session sndfile sni soundtouch spell sse ssl startup-notification svg sysfs tcpd theora tiff truetype unicode usb v4l v4l2 vcd vhosts vorbis wmf x264 x86 xcb xinerama xml xorg xulrunner xv xvid xvmc zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_US en_GB nl de" RUBY_TARGETS="ruby18" SANE_BACKENDS="pixma" USERLAND="GNU" VIDEO_CARDS="vesa fbdev v4l nv nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Comment 1 Jeroen Roovers (RETIRED) gentoo-dev 2010-10-07 14:50:59 UTC
What if you want two files examined:

$ file metadata.xml foobar; echo $?
metadata.xml: XML  document text
foobar:       cannot open `foobar' (No such file or directory)

Since apparently file was designed this way, it's not a Gentoo bug. Most shells have their own means to figure out whether a file exists, so this is rather easy to work around.
Comment 2 Evert 2010-10-07 19:45:20 UTC
What about:

$ cat no-file && echo OK || echo NOK
cat: no-file: No such file or directory

$ file no-file && echo OK || echo NOK
no-file: cannot open `no-file' (No such file or directory)

I agree, it's not gentoo's fault, it's a developers bug.
I'm not sure why you say "works for me"...
Comment 3 Evert 2010-10-08 20:39:52 UTC
Jeroen, can you please tell me, if "No such file or directory" is not an error, what would be an error?

And of course there is an easy workaround, but if a workaround is needed, doesn't that mean this actually _is_ a bug?
Comment 4 Evert 2010-10-09 01:22:58 UTC
Never mind, I contacted the author.
According to
    If the file named by the file operand does not exist, cannot be read,
    or the type of the file named by the file operand cannot be determined,
    this shall not be considered an error that affects the exit status.

So, this is not in line with ls, cat, grep, cp, chmod, gzip, gunzip, cut, head, stat, wc, etc. which all return with a non-zero exit status when any of the given files does not exist.