From owner-freebsd-stable@FreeBSD.ORG Sat Mar 5 21:15:04 2011 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2001:4f8:fff6::35]) by hub.freebsd.org (Postfix) with ESMTP id 6615F106564A for ; Sat, 5 Mar 2011 21:15:04 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from doug-optiplex.ka9q.net (hub.freebsd.org [IPv6:2001:4f8:fff6::36]) by mx2.freebsd.org (Postfix) with ESMTP id 2CD8414E19A; Sat, 5 Mar 2011 21:15:04 +0000 (UTC) Message-ID: <4D72A7D7.4000907@FreeBSD.org> Date: Sat, 05 Mar 2011 13:15:03 -0800 From: Doug Barton Organization: http://SupersetSolutions.com/ User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.15) Gecko/20110304 Thunderbird/3.1.9 MIME-Version: 1.0 To: Jilles Tjoelker References: <4D6BD83B.3040609@missouri.edu> <20110304190545.GA38881@stack.nl> In-Reply-To: <20110304190545.GA38881@stack.nl> X-Enigmail-Version: 1.1.2 OpenPGP: id=1A1ABC84 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Stable Subject: Re: Change in behavior to stat(1) X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Mar 2011 21:15:04 -0000 On 03/04/2011 11:05, Jilles Tjoelker wrote: > On Mon, Feb 28, 2011 at 11:15:39AM -0600, Stephen Montgomery-Smith wrote: >> I had a little script that would remove broken links. I used to do it >> like this: > >> if ! stat -L $link> /dev/null; then rm $link; fi > >> But recently (some time in February according to the CVS records) stat >> was changed so that stat -L would use lstat(2) if the link is broken. > >> So I had to change it to > >> if stat -L $link | awk '{print $3}' | grep l> /dev/null; >> then rm $link; fi > >> but it is a lot less elegant. > >> What is the proper accepted way to remove broken links? > > A better answer to your original question was already given, but for > that command, isn't it sufficient to do > > if ! [ -e $link ]; then rm $link; fi > > All test(1)'s primaries that test things about files follow symlinks, > except for -h/-L. I'd do '[ -e "$link" ] || unlink $link' but Jilles is definitely right that simply using 'test -e' is the way to go. Stephen, sorry to hear that the change in behavior to stat(1) was troubling to you. A little bit of the history might be useful. I originally imported stat(1) from NetBSD in 2002, but did not keep up with the improvements that NetBSD made to it. I recently found time to catch up with the work that they've done, and the change to the behavior of readlink seemed like a useful one so I brought it over. hopefully it won't cause too many more problems. :) Doug -- Nothin' ever doesn't change, but nothin' changes much. -- OK Go Breadth of IT experience, and depth of knowledge in the DNS. Yours for the right price. :) http://SupersetSolutions.com/