WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [Patch] fix canonicalize-existing vbd file

To: Keir Fraser <Keir.Fraser@xxxxxxxxxxxx>
Subject: Re: [Xen-devel] [Patch] fix canonicalize-existing vbd file
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Wed, 5 Dec 2007 14:26:50 +0000
Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>, Akio Takebe <takebe_akio@xxxxxxxxxxxxxx>
Delivery-date: Wed, 05 Dec 2007 06:29:28 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <C37C6243.196D0%Keir.Fraser@xxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Newsgroups: chiark.mail.xen.devel
References: <2C83747DEF0A9takebe_akio@xxxxxxxxxxxxxx> <C37C6243.196D0%Keir.Fraser@xxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Keir Fraser writes ("Re: [Xen-devel] [Patch] fix canonicalize-existing vbd 
file"):
> Do you mean to 'test -f "$file"'? A symlink will always fail 'test -f', and
> $p can be a symlink.

test -f calls stat(2) rather than lstat(2) and only falls back to the
latter if the former fails.  So if the argument is a link which can be
dereferenced, test -f tells you whether the link target is a file.

If you want to know whether $file is a file or a symlink to a file
   test -f "$file"
precisely wrong as it is true in both those cases.

See
    http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
which says
     With the exception of the -h file and -L file primaries, if a
     file argument is a symbolic link, test shall evaluate the
     expression by resolving the symbolic link and using the file
     referenced by the link.

It's actually true, too:

mariner:~/junk> touch a 
mariner:~/junk> ln -s a b
mariner:~/junk> test -f a && echo file
file
mariner:~/junk> test -f b && echo file
file
mariner:~/junk> test -L b && echo link
link
mariner:~/junk> ln -s enoent c
mariner:~/junk> test -f c && echo file
mariner:~/junk> test -L c && echo link
link
mariner:~/junk>

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel