From owner-freebsd-stable@FreeBSD.ORG Mon Feb 28 23:32:14 2011 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EC72D106566B for ; Mon, 28 Feb 2011 23:32:14 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from qmta06.emeryville.ca.mail.comcast.net (qmta06.emeryville.ca.mail.comcast.net [76.96.30.56]) by mx1.freebsd.org (Postfix) with ESMTP id CE9E98FC1C for ; Mon, 28 Feb 2011 23:32:14 +0000 (UTC) Received: from omta23.emeryville.ca.mail.comcast.net ([76.96.30.90]) by qmta06.emeryville.ca.mail.comcast.net with comcast id DbCm1g0031wfjNsA6bYEU3; Mon, 28 Feb 2011 23:32:14 +0000 Received: from koitsu.dyndns.org ([98.248.33.18]) by omta23.emeryville.ca.mail.comcast.net with comcast id DbY81g00D0PUQVN8jbY9AW; Mon, 28 Feb 2011 23:32:11 +0000 Received: by icarus.home.lan (Postfix, from userid 1000) id D7A619B427; Mon, 28 Feb 2011 15:32:07 -0800 (PST) Date: Mon, 28 Feb 2011 15:32:07 -0800 From: Jeremy Chadwick To: Stephen Montgomery-Smith Message-ID: <20110228233207.GA33800@icarus.home.lan> References: <4D6BD83B.3040609@missouri.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4D6BD83B.3040609@missouri.edu> User-Agent: Mutt/1.5.21 (2010-09-15) 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: Mon, 28 Feb 2011 23:32:15 -0000 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? If your complaint is the literal length of the line, you should be able to change your one-liner to: if stat -L -f %Sp $link | grep l > /dev/null; then rm $link; fi Though I agree this is less elegant. Unrelated (but worth noting), be aware your one-liner will break horribly with files that contains spaces; use "$link" instead. Possibly you could use the example from the find(1) man page: find -L /usr/ports/packages -type l -exec rm -- {} + Delete all broken symbolic links in /usr/ports/packages. (Note that the "+" on the end is not a typo, see the man page) Otherwise, possibly someone should add a flag to stat(1) that inhibits falling back on lstat(2). -- | Jeremy Chadwick jdc@parodius.com | | Parodius Networking http://www.parodius.com/ | | UNIX Systems Administrator Mountain View, CA, USA | | Making life hard for others since 1977. PGP 4BD6C0CB |