From owner-freebsd-java Fri Jun 2 9:30:19 2000 Delivered-To: freebsd-java@freebsd.org Received: from ares.trc.adelaide.edu.au (ares.trc.adelaide.edu.au [129.127.246.5]) by hub.freebsd.org (Postfix) with ESMTP id 819A337BA07 for ; Fri, 2 Jun 2000 09:30:13 -0700 (PDT) (envelope-from glewis@ares.trc.adelaide.edu.au) Received: (from glewis@localhost) by ares.trc.adelaide.edu.au (8.9.3/8.9.3) id CAA22648; Sat, 3 Jun 2000 02:00:05 +0930 (CST) (envelope-from glewis) From: Greg Lewis Message-Id: <200006021630.CAA22648@ares.trc.adelaide.edu.au> Subject: Re: can't remove directories? In-Reply-To: <3937D0EA.D9D1E8BE@ox.com> from Rob Furphy at "Jun 2, 2000 11:21:14 am" To: Rob Furphy Date: Sat, 3 Jun 2000 02:00:04 +0930 (CST) Cc: freebsd-java@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL70 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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