From owner-freebsd-hackers Tue Jan 16 7:51:31 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from smtp.nettoll.com (matrix.nettoll.net [212.155.143.61]) by hub.freebsd.org (Postfix) with ESMTP id 6864A37B402 for ; Tue, 16 Jan 2001 07:51:11 -0800 (PST) Received: by smtp.nettoll.com; Tue, 16 Jan 2001 16:47:20 +0100 (MET) Message-Id: <4.3.0.20010116164550.07174e40@pop.free.fr> X-Sender: usebsd@pop.free.fr X-Mailer: QUALCOMM Windows Eudora Version 4.3 Date: Tue, 16 Jan 2001 16:57:19 +0100 To: Peter Pentchev From: mouss Subject: Re: pppd & mkdir diff Cc: "W.H.Scholten" , Alfred Perlstein , freebsd-hackers@FreeBSD.ORG In-Reply-To: <20010116145020.E364@ringworld.oblivion.bg> References: <4.3.0.20010116131322.03f23a80@pop.free.fr> <3A5C843C.794BDF32@xs4all.nl> <20010111132509.J7240@fw.wintelcom.net> <3A5EE6B1.41C67EA6@xs4all.nl> <20010112081422.U7240@fw.wintelcom.net> <3A6025F1.794BDF32@xs4all.nl> <4.3.0.20010116131322.03f23a80@pop.free.fr> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG At 14:50 16/01/01 +0200, Peter Pentchev wrote: >As somebody already pointed out, there *is* a dirname(3) function, and even >a dirname(1) cmdline utility to invoke it. oops. I'll need to stay current:) >In a followup to Alfred's mkdir(1) commit, I sent a sample implementation >of a direxname() function, which calls dirname(3) in a loop, and returns >the longest existing path component. I'll get back to him shortly >with a patch to mkdir(1) using direxname() to report a meaningful error >message, something like "Cannot create /exists/nonex/foo/bar, nonexistent >path components after /exists". In the meantime, attached is my first >shot at direxname() implementation, using dirname(3)'s static buffer. I'm not convinced you really need to check which is the "largest" parent that exists. if /a doesn't exist, and I do a mkdir /a/b/c/d, just a "/a/b/c does not exist" is far sufficient. For me, if you ignore permissions and the like, the condition to create a directory is that its parent exists, whatever are his grand-parents. after the error is shown, one will anyway check which dirs exist. doing the stat() on all those just consumes time, with few benefits. on an NFS mounted fs, this would be just annoyiing sometimes. now if you really insist, I'd suggest doing the stat the other way: check the root, then its children, then the children of the latter... like in mkdir -p. at last, note that there might be race conditions while you stat(). but there is hardly a way to avoid'em. at least, a single stat() reduces the window of opportunity. regards, mouss To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message