Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 02 Jun 2000 14:28:29 -0400
From:      Rob Furphy <rcf@ox.com>
To:        Greg Lewis <glewis@trc.adelaide.edu.au>, "freebsd-java@FreeBSD.ORG" <freebsd-java@FreeBSD.ORG>
Subject:   Re: can't remove directories? (Better fix)
Message-ID:  <3937FCCD.5223CCF1@ox.com>
References:  <200006021640.CAA31260@ares.trc.adelaide.edu.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3937FCCD.5223CCF1>