From owner-freebsd-hackers@FreeBSD.ORG Fri May 24 10:24:27 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E571FC97; Fri, 24 May 2013 10:24:27 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (unknown [IPv6:2001:610:1108:5012::107]) by mx1.freebsd.org (Postfix) with ESMTP id AE1231E5; Fri, 24 May 2013 10:24:27 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 7358F1203CF; Fri, 24 May 2013 12:24:11 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 5CA7028493; Fri, 24 May 2013 12:24:11 +0200 (CEST) Date: Fri, 24 May 2013 12:24:11 +0200 From: Jilles Tjoelker To: John Baldwin Subject: Re: find -delete broken, or just used improperly? Message-ID: <20130524102411.GA3984@stack.nl> References: <20130520192316.GA32531@pix.net> <20130520214731.GA43407@stack.nl> <201305211106.39313.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201305211106.39313.jhb@freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-hackers@freebsd.org, Kurt Lidl X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 May 2013 10:24:28 -0000 On Tue, May 21, 2013 at 11:06:39AM -0400, John Baldwin wrote: > On Monday, May 20, 2013 5:47:31 pm Jilles Tjoelker wrote: > > The below patch allows deleting the pathname given to find itself: > > Index: usr.bin/find/function.c > > =================================================================== > > --- usr.bin/find/function.c (revision 250661) > > +++ usr.bin/find/function.c (working copy) > > @@ -442,7 +442,8 @@ > > errx(1, "-delete: forbidden when symlinks are followed"); > > > > /* Potentially unsafe - do not accept relative paths whatsoever */ > > - if (strchr(entry->fts_accpath, '/') != NULL) > > + if (entry->fts_level > FTS_ROOTLEVEL && > > + strchr(entry->fts_accpath, '/') != NULL) > > errx(1, "-delete: %s: relative path potentially not safe", > > entry->fts_accpath); > I'm curious, how would you instruct a patched find to avoid deleteing > the /tmp/foo directory (e.g. if you wanted this to be a job that > pruned empty dirs from /tmp/foo but never pruned the directory > itself). Would -mindepth 1 do it? (Just asking. I have also found > this message annoying but most of the jobs I have seen it on probably > don't want to delete the root path, just descendants.) -mindepth 1 works, as does cd /tmp/foo && find . -... (-delete silently ignores . and ..). -- Jilles Tjoelker