Subject: Re: bug#10470: MSYS: race in directory access?

From: Peter Rosin <[email-masked]>
Date: Tue, 10 Jan 2012 00:15:55 +0100

Peter Rosin skrev 2012-01-10 00:07:
> Hi!
> 
> distcheck-configure-flags-am.test fails on MSYS.  I think the cause is
> that some process lingers with CWD in the _build directory which some
> other process tries to remove.  On MSYS, it's not possible to remove a
> directory that is "in use" like that.
> 
> Ugly patch coming up shortly.

As promised.

Cheers,
Peter

>From 8ba67ab9885c8987d7a09ad650bcda69675b8285 Mon Sep 17 00:00:00 2001
From: Peter Rosin <[email-masked]>
Date: Tue, 10 Jan 2012 00:14:08 +0100
Subject: [PATCH] dist: try to avoid race on MSYS when removing the distdir

Fixes automake bug#10470.

lib/am/distdir.am (am__remove_distdir): Add a short sleep to make old
processes release the directory before an attempt to remove it is made.
On MSYS, it is not possible to remove a directory that is "in use".
---
 lib/am/distdir.am |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/am/distdir.am b/lib/am/distdir.am
index d8c1a89..e56d33b 100644
--- a/lib/am/distdir.am
+++ b/lib/am/distdir.am
@@ -22,10 +22,13 @@ if %?TOPDIR_P%
 distdir = $(PACKAGE)-$(VERSION)
 top_distdir = $(distdir)
 
+## On MSYS (1.0.17) it is not possible to remove a directory that is
+## in use, hence the sleep call, which gives processes time to exit
+## and "release" the directory before it is removed.
 am__remove_distdir = \
   { test ! -d "$(distdir)" \
     || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
-         && rm -fr "$(distdir)"; }; }
+         && sleep 1 && rm -fr "$(distdir)"; }; }
 am__post_remove_distdir = $(am__remove_distdir)
 endif %?TOPDIR_P%
 
-- 
1.7.5.1