removing open files

Joe Buehler jbuehler@hekimian.com
Wed Mar 26 13:12:00 GMT 2003


The following script demonstrates a bug under NT -- the final rm goes
into an infinite loop because there is an open file in the directory
being removed.

#!/bin/bash
set -x
rm -fr /tmp/junk.dir
mkdir /tmp/junk.dir
# try to remove a directory containing an open file
rm -fr /tmp/junk.dir >/tmp/junk.dir/junk.file

I believe the only solution to this is to move files elsewhere before
they are deleted.  As long as there is something open under a directory,
Windows appears to lock the directory, and it cannot be removed -- which
is not UNIX behavior, and will break programs that depend on UNIX
behavior.

I have a simple patch to fix this.  It looks for a specially-named
directory at the root of the drive holding the file, and moves it there
before deleting the file.  Any failures encountered (e.g. directory doesn't
exist) cause reversion to the current behavior.

Can we re-open the discussion on this and get a final fix into Cygwin?
-- 
Joe Buehler



More information about the Cygwin-developers mailing list