8129633: (fs) Investigate removing the GNOME-based FileTypeDetector from the Linux and Solaris implementations
Summary: Remove the GNOME VFS detector leaving the libgio detector in place.
Reviewed-by: chegar
--- a/jdk/make/mapfiles/libnio/mapfile-linux Thu Aug 06 14:35:04 2015 -0400
+++ b/jdk/make/mapfiles/libnio/mapfile-linux Thu Aug 06 12:35:59 2015 -0700
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -135,9 +135,7 @@
Java_sun_nio_ch_UnixAsynchronousServerSocketChannelImpl_initIDs;
Java_sun_nio_ch_UnixAsynchronousSocketChannelImpl_checkConnect;
Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs;
+ Java_sun_nio_fs_GnomeFileTypeDetector_probeGio;
Java_sun_nio_fs_MagicFileTypeDetector_initialize0;
Java_sun_nio_fs_MagicFileTypeDetector_probe0;
Java_sun_nio_fs_LinuxWatchService_eventSize;
--- a/jdk/make/mapfiles/libnio/mapfile-solaris Thu Aug 06 14:35:04 2015 -0400
+++ b/jdk/make/mapfiles/libnio/mapfile-solaris Thu Aug 06 12:35:59 2015 -0700
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -130,9 +130,7 @@
Java_sun_nio_ch_SolarisEventPort_port_1getn;
Java_sun_nio_ch_SolarisEventPort_port_1send;
Java_sun_nio_fs_GnomeFileTypeDetector_initializeGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio;
- Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs;
- Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs;
+ Java_sun_nio_fs_GnomeFileTypeDetector_probeGio;
Java_sun_nio_fs_UnixNativeDispatcher_init;
Java_sun_nio_fs_UnixNativeDispatcher_getcwd;
Java_sun_nio_fs_UnixNativeDispatcher_strerror;
--- a/jdk/src/java.base/unix/classes/sun/nio/fs/GnomeFileTypeDetector.java Thu Aug 06 14:35:04 2015 -0400
+++ b/jdk/src/java.base/unix/classes/sun/nio/fs/GnomeFileTypeDetector.java Thu Aug 06 12:35:59 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,34 +31,23 @@
import java.security.PrivilegedAction;
/**
- * File type detector that uses the GNOME I/O library or the deprecated
- * GNOME VFS to guess the MIME type of a file.
+ * File type detector that uses the GNOME I/O library to guess the
+ * MIME type of a file.
*/
public class GnomeFileTypeDetector
extends AbstractFileTypeDetector
{
- private static final String GNOME_VFS_MIME_TYPE_UNKNOWN =
- "application/octet-stream";
-
- // true if GIO available
+ // true if GIO is available
private final boolean gioAvailable;
- // true if GNOME VFS available and GIO is not available
- private final boolean gnomeVfsAvailable;
-
public GnomeFileTypeDetector() {
gioAvailable = initializeGio();
- if (gioAvailable) {
- gnomeVfsAvailable = false;
- } else {
- gnomeVfsAvailable = initializeGnomeVfs();
- }
}
@Override
public String implProbeContentType(Path obj) throws IOException {
- if (!gioAvailable && !gnomeVfsAvailable)
+ if (!gioAvailable)
return null;
if (!(obj instanceof UnixPath))
return null;
@@ -66,18 +55,10 @@
UnixPath path = (UnixPath)obj;
NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls());
try {
- if (gioAvailable) {
- // GIO may access file so need permission check
- path.checkRead();
- byte[] type = probeUsingGio(buffer.address());
- return (type == null) ? null : Util.toString(type);
- } else {
- byte[] type = probeUsingGnomeVfs(buffer.address());
- if (type == null)
- return null;
- String s = Util.toString(type);
- return s.equals(GNOME_VFS_MIME_TYPE_UNKNOWN) ? null : s;
- }
+ // GIO may access file so need permission check
+ path.checkRead();
+ byte[] type = probeGio(buffer.address());
+ return (type == null) ? null : Util.toString(type);
} finally {
buffer.release();
}
@@ -86,11 +67,7 @@
// GIO
private static native boolean initializeGio();
- private static native byte[] probeUsingGio(long pathAddress);
-
- // GNOME VFS
- private static native boolean initializeGnomeVfs();
- private static native byte[] probeUsingGnomeVfs(long pathAddress);
+ private static native byte[] probeGio(long pathAddress);
static {
AccessController.doPrivileged(new PrivilegedAction<>() {
--- a/jdk/src/java.base/unix/native/libnio/fs/GnomeFileTypeDetector.c Thu Aug 06 14:35:04 2015 -0400
+++ b/jdk/src/java.base/unix/native/libnio/fs/GnomeFileTypeDetector.c Thu Aug 06 12:35:59 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,11 @@
#include <string.h>
#endif
+/*
+ * For reference see for example the GFileInfo section at
+ * https://developer.gnome.org/gio/unstable/.
+ */
+
/* Definitions for GIO */
#define G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "standard::content-type"
@@ -68,18 +73,6 @@
static g_file_info_get_content_type_func g_file_info_get_content_type;
-/* Definitions for GNOME VFS */
-
-typedef int gboolean;
-
-typedef gboolean (*gnome_vfs_init_function)(void);
-typedef const char* (*gnome_vfs_mime_type_from_name_function)
- (const char* filename);
-
-static gnome_vfs_init_function gnome_vfs_init;
-static gnome_vfs_mime_type_from_name_function gnome_vfs_mime_type_from_name;
-
-
#include "sun_nio_fs_GnomeFileTypeDetector.h"
@@ -127,7 +120,7 @@
}
JNIEXPORT jbyteArray JNICALL
-Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGio
+Java_sun_nio_fs_GnomeFileTypeDetector_probeGio
(JNIEnv* env, jclass this, jlong pathAddress)
{
char* path = (char*)jlong_to_ptr(pathAddress);
@@ -153,52 +146,3 @@
return result;
}
-
-JNIEXPORT jboolean JNICALL
-Java_sun_nio_fs_GnomeFileTypeDetector_initializeGnomeVfs
- (JNIEnv* env, jclass this)
-{
- void* vfs_handle;
-
- vfs_handle = dlopen("libgnomevfs-2.so", RTLD_LAZY);
- if (vfs_handle == NULL) {
- vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
- }
- if (vfs_handle == NULL) {
- return JNI_FALSE;
- }
-
- gnome_vfs_init = (gnome_vfs_init_function)dlsym(vfs_handle, "gnome_vfs_init");
- gnome_vfs_mime_type_from_name = (gnome_vfs_mime_type_from_name_function)
- dlsym(vfs_handle, "gnome_vfs_mime_type_from_name");
-
- if (gnome_vfs_init == NULL ||
- gnome_vfs_mime_type_from_name == NULL)
- {
- dlclose(vfs_handle);
- return JNI_FALSE;
- }
-
- (*gnome_vfs_init)();
- return JNI_TRUE;
-}
-
-JNIEXPORT jbyteArray JNICALL
-Java_sun_nio_fs_GnomeFileTypeDetector_probeUsingGnomeVfs
- (JNIEnv* env, jclass this, jlong pathAddress)
-{
- char* path = (char*)jlong_to_ptr(pathAddress);
- const char* mime = (*gnome_vfs_mime_type_from_name)(path);
-
- if (mime == NULL) {
- return NULL;
- } else {
- jbyteArray result;
- jsize len = strlen(mime);
- result = (*env)->NewByteArray(env, len);
- if (result != NULL) {
- (*env)->SetByteArrayRegion(env, result, 0, len, (jbyte*)mime);
- }
- return result;
- }
-}
--- a/jdk/test/java/nio/file/Files/probeContentType/Basic.java Thu Aug 06 14:35:04 2015 -0400
+++ b/jdk/test/java/nio/file/Files/probeContentType/Basic.java Thu Aug 06 12:35:59 2015 -0700
@@ -22,7 +22,7 @@
*/
/* @test
- * @bug 4313887 8129632
+ * @bug 4313887 8129632 8129633
* @summary Unit test for probeContentType method
* @library ../..
* @build Basic SimpleFileTypeDetector