From owner-freebsd-java Fri Jun 2 11:28:37 2000 Delivered-To: freebsd-java@freebsd.org Received: from firewall.ox.com (firewall.ox.com [129.77.1.1]) by hub.freebsd.org (Postfix) with ESMTP id D980837BB04 for ; Fri, 2 Jun 2000 11:28:32 -0700 (PDT) (envelope-from rcf@ox.com) Received: from firewall.ox.com (root@localhost) by firewall.ox.com with ESMTP id OAA20778 for ; Fri, 2 Jun 2000 14:28:31 -0400 (EDT) Received: from pur-wk-rfurphy.ny.ox.com (pur-wk-rfurphy.ny.ox.com [129.77.2.133]) by firewall.ox.com with ESMTP id OAA20772 for ; Fri, 2 Jun 2000 14:28:30 -0400 (EDT) Received: from ox.com (localhost.ny.ox.com [127.0.0.1]) by pur-wk-rfurphy.ny.ox.com (8.9.3/8.9.3) with ESMTP id OAA29882; Fri, 2 Jun 2000 14:28:29 -0400 (EDT) (envelope-from rcf@ox.com) Message-ID: <3937FCCD.5223CCF1@ox.com> Date: Fri, 02 Jun 2000 14:28:29 -0400 From: Rob Furphy X-Mailer: Mozilla 4.73 [en] (X11; U; FreeBSD 3.4-RELEASE i386) X-Accept-Language: en MIME-Version: 1.0 To: Greg Lewis , "freebsd-java@FreeBSD.ORG" Subject: Re: can't remove directories? (Better fix) References: <200006021640.CAA31260@ares.trc.adelaide.edu.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Ahh...it's very clear now what was going on. The answer was right in front of me. Good hunting. I have made changes to your fix. Instead of blindly trying both file and directory deletes on the specified path, this fix discovers what the path is(dir or not) and does the appropriate thing. Not good with diff (and don't want to get this wrong), so below is the new versions of both functions. JNIEXPORT jboolean JNICALL Java_java_io_UnixFileSystem_delete(JNIEnv *env, jobject this, jobject file) { 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 identifying if we have a directory or not. */ struct stat sb; if(stat(path, &sb) == 0) { int fmt = sb.st_mode & S_IFMT; if(fmt == S_IFDIR) { if(rmdir(path) == 0) { rv = JNI_TRUE; } } else { if(unlink(path) == 0) { rv = JNI_TRUE; } } #else if(remove(path) == 0) { #endif rv = JNI_TRUE; } } END_PLATFORM_STRING(env, path); return rv; } JNIEXPORT jboolean JNICALL Java_java_io_UnixFileSystem_deleteOnExit(JNIEnv *env, jobject this, 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 identifying if we have a directory or not. */ struct stat sb; if(stat(path, &sb) == 0) { int fmt = sb.st_mode & S_IFMT; if(fmt == S_IFDIR) { deleteOnExit(env, path, rmdir); } else { deleteOnExit(env, path, unlink); } } #else deleteOnExit(env, path, remove); #endif } END_PLATFORM_STRING(env, path); return JNI_TRUE; } Now can I get back to work, please? *grin* Rob F To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message