Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Jun 2000 02:00:04 +0930 (CST)
From:      Greg Lewis <glewis@trc.adelaide.edu.au>
To:        Rob Furphy <rcf@ox.com>
Cc:        freebsd-java@FreeBSD.ORG
Subject:   Re: can't remove directories?
Message-ID:  <200006021630.CAA22648@ares.trc.adelaide.edu.au>
In-Reply-To: <3937D0EA.D9D1E8BE@ox.com> from Rob Furphy at "Jun 2, 2000 11:21:14 am"

next in thread | previous in thread | raw e-mail | index | archive | help
Rob Furphy wrote:
> Your patch works for File.delete().

I've changed it a bit.  Added a comment and used unlink rather than remove
to show explicitly the difference and because remove is just an alias for
unlink anyway.

> Here's another problem  File.deleteOnExit()
> has the same problem...even with the patch applied.  I've spent
> about 2 hours looking and I can't find a fix.  Got to get to work
> now so I have to stop.

Yep, that one is different.  But I've got a patch for that too now :).

> The problem is that deleteOnExit() deletes files specified
> but not directories specified.

Here is the complete patch.  Works for me.  You probably only want the
second hunk since the first is the equivalent part of the previous patch.

Possible criticism is that it doubles the entries in the list to delete
when exiting.  I guess the counter is that something is a directory when
I initially schedule it for deletion and I change it to a file later (or
vice versa) then the list would have the wrong entry if the list got unlink 
or rmdir as appropriate when the list was set up.

I'll commit this fairly soon unless someone points out a huge flaw :)

Index: src/freebsd/native/java/io/UnixFileSystem_md.c
===================================================================
RCS file: /data/java/JDK2/javasrc/src/freebsd/native/java/io/UnixFileSystem_md.c,v
retrieving revision 1.3
diff -u -r1.3 UnixFileSystem_md.c
--- src/freebsd/native/java/io/UnixFileSystem_md.c	2000/04/13 14:05:57	1.3
+++ src/freebsd/native/java/io/UnixFileSystem_md.c	2000/06/02 16:23:50
@@ -237,7 +237,17 @@
     jboolean rv = JNI_FALSE;
 
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
+#ifdef __FreeBSD__
+        /*
+	 * Under FreeBSD remove(3) is simply an alias for unlink(2).  This
+	 * is not the case on Linux and Solaris where remove() calls unlink()
+	 * for files and rmdir() for directories.  Duplicate this functionality
+	 * here by trying rmdir should unlink fail.
+	 */
+	if (unlink(path) == 0 || rmdir(path) == 0) {
+#else
 	if (remove(path) == 0) {
+#endif
 	    rv = JNI_TRUE;
 	}
     } END_PLATFORM_STRING(env, path);
@@ -250,7 +260,17 @@
 					 jobject file)
 {
     WITH_FIELD_PLATFORM_STRING(env, file, ids.path, path) {
+#ifdef __FreeBSD__
+        /*
+	 * Under FreeBSD remove(3) is simply an alias for unlink(2).  This
+	 * is not the case on Linux and Solaris where remove() calls unlink()
+	 * for files and rmdir() for directories.  Duplicate this functionality
+	 * here by trying rmdir should unlink fail.
+	deleteOnExit(env, path, unlink);
+	deleteOnExit(env, path, rmdir);
+#else
 	deleteOnExit(env, path, remove);
+#endif
     } END_PLATFORM_STRING(env, path);
     return JNI_TRUE;
 }

-- 
Greg Lewis 				glewis@trc.adelaide.edu.au
Computing Officer			+61 8 8303 5083
Teletraffic Research Centre


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200006021630.CAA22648>