Subject: Re: infinite loop in rm
From: Joe Buehler <[email-masked]>
To: [email-masked]
Date: Mon, 18 Nov 2002 17:16:01 -0500

William A. Hoffman wrote:

> I saw some mention of this problem here:
> http://www.cygwin.com/ml/cygwin/2002-07/msg00147.html
> 
> Is there a fix for this that works, or will be incorporated 
> into a future version of cygwin?  I looked in the FAQ and
> saw nothing about it.   I have some nightly scripts that clean
> some directories, and if I leave a shell open in one of the
> directories, the scripts just run forever trying to remove
> the directory.

I am using the following patch to unlink() on a version of Cygwin that
is several months old.  It does nothing unless there is a directory
named .cygdel at the root of the drive holding the file to be deleted.
In that case, it moves the file there before trying to delete it.

Make sure you make the directory mode 777 when you create it...

Works for me -- I think I posted this to the list but may be wrong.

Joe Buehler

Index: src/winsup/cygwin/syscalls.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/syscalls.cc,v
retrieving revision 1.214
diff -u -r1.214 syscalls.cc
--- src/winsup/cygwin/syscalls.cc	2 Jul 2002 03:06:32 -0000	1.214
+++ src/winsup/cygwin/syscalls.cc	8 Aug 2002 16:38:12 -0000
@@ -142,6 +142,23 @@
  	SetFileAttributes (win32_name, (DWORD) win32_name & ~FILE_ATTRIBUTE_READONLY);
      }

+  // attempt to rename before deleting
+  char *basename;
+  basename = strrchr(win32_name, '\\');
+  if (basename && *++basename) {
+    const char *rootdir = win32_name.root_dir();
+    if (rootdir) {
+      const char *s = strrchr(rootdir, '\\');
+      if (s && !s[1]) {
+	char newname[MAX_PATH + 12];
+	__small_sprintf(newname, "%s.cygdel\\%s", rootdir, basename);
+	if (MoveFile(win32_name.get_win32(), newname)) {
+	  win32_name.check(newname, PC_SYM_NOFOLLOW | PC_FULL);
+	}
+      }
+    }
+  }
+
    DWORD lasterr;
    lasterr = 0;
    for (int i = 0; i < 2; i++)

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/