This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
patch for infinite loop in unlink()
- From: Joe Buehler <jbuehler at hekimian dot com>
- To: cygwin-patches at cygwin dot com
- Date: Thu, 08 Aug 2002 09:39:03 -0400
- Subject: patch for infinite loop in unlink()
- Organization: Spirent Communications
- Reply-to: joseph dot buehler at spirentcom dot com
Here is a patch for the problem of "rm -fr" getting into an infinite loop
when it tries to delete a file that is open.
It is a little incomplete in that it depends on the existence of a directory
named .cygdel in the root directory of the involved drive, but does not
attempt to create the directory. So some solution is needed for that.
The patch code has no effect if anything fails.
It has worked for me for some time now, but definitely needs to be
checked by someone who knows the guts of the code involved.
Please critique...
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 13:31:35 -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++)