X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-3.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: [1.7] deleting in-use directories Date: Thu, 9 Apr 2009 16:13:20 +0000 (UTC) Lines: 86 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com The Autoconf testsuite is failing several tests on cygwin 1.7 that used to pass on cygwin 1.5. I've traced it to the fact that 1.7 is trying to be smarter about deleting in-use files and directories, but doesn't quite get things right. First, a test case run on Solaris (I haven't run it on Linux, but suspect similar semantics). To demo this, I need two terminals, with prompts designated 1$ and 2$. 1$ cd /tmp 1$ mkdir foo 1$ cd foo 1$ touch bar 1$ ls bar 2$ cd /tmp 2$ rm -Rf foo # here is where cygwin 1.5 would fail, as allowed by POSIX 2$ ls foo ls: foo: No such file or directory 1$ ls ls: reading directory .: Stale NFS file handle 2$ mkdir foo 2$ cd foo 2$ touch blah 2$ ls blah 1$ ls ls: reading directory .: Stale NFS file handle But when repeating the same test on cygwin: 1$ cd /tmp 1$ mkdir foo 1$ cd foo 1$ touch bar 1$ ls bar 2$ cd /tmp 2$ rm -Rf foo # succeeds due to new 1.7 magic 2$ ls foo ls: cannot open directory foo: Permission denied 2$ ls -dF fo? foo/ Oops; the directory is still showing up in a readdir listing, rather than disappearing altogether. This violates POSIX - if the rmdir was successful, then the same process must no longer see that name on a successive readdir. If the name still exists, then the rmdir should have failed. 1$ ls ls: cannot open directory .: Permission denied OK, the failure in the first terminal is consistent with Solaris - since the current working directory was deleted out from under our feet by another process, we are allowed to be unable to opendir("."). 2$ mkdir foo mkdir: cannot create directory `foo': Permission denied Ouch - that is the real failure that cripples the autoconf testsuite. The testsuite tolerates the inability to delete a directory because some process has it open, because it can then reuse that directory. It also tolerates deleting the directory and recreating a new one by the same name. But it falls flat if it successfully deletes the directory, but can't recreate a new one until the first process closes its stale handle (either by exiting, or by using chdir). The nicest thing would be figuring out how to make readdir refuse to list directories that have been deleted but still have open handles, and to also allow the recreation of a new directory by the same name. But if we can't achieve that due to Windows semantics, then I would much rather go back to cygwin 1.5 behavior of refusing to delete directories with open handles, as that is permitted by POSIX, rather than the current state of affairs which violates POSIX and breaks the autoconf testsuite. Similar comments probably apply to unlink and regular files, although I suspect that the restrictions imposed by Windows on regular files will be different than those imposed on directories. -- Eric Blake -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/