### Eclipse Workspace Patch 1.0 #P org.eclipse.core.filesystem Index: natives/unix/localfile.c =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/natives/unix/localfile.c,v retrieving revision 1.5 diff -u -r1.5 localfile.c --- natives/unix/localfile.c 29 Jan 2007 23:21:08 -0000 1.5 +++ natives/unix/localfile.c 30 Jan 2007 12:25:13 -0000 @@ -41,6 +41,24 @@ return result; } +#ifdef LINUX +/* + * Get a Java String from a java byte array, using the default charset. + * Uses Convert.fromPlatformBytes([B). + */ +jstring getString(JNIEnv *env, jbyteArray source) { + static jclass clsConvert = 0; + static jmethodID midFromPlatformBytes = 0; + if (midFromPlatformBytes == 0) { + clsConvert = (*env)->FindClass(env, "org/eclipse/core/internal/filesystem/local/Convert"); + if (clsConvert == 0) return NULL; + midFromPlatformBytes = (*env)->GetStaticMethodID(env, clsConvert, "fromPlatformBytes", "([B)Ljava/lang/String;"); + if (midFromPlatformBytes == 0) return NULL; + } + return (*env)->CallStaticObjectMethod(env, clsConvert, midFromPlatformBytes, source); +} +#endif + /* * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives * Method: internalIsUnicode @@ -147,17 +165,15 @@ //symbolic link: read link target char buf[PATH_MAX+1]; int len; + jbyteArray barr; len = readlink((const char*)name, buf, PATH_MAX); if (len>0) { - buf[len]=0; + barr = (*env)->NewByteArray(env, len); + (*env)->SetByteArrayRegion(env, barr, 0, len, buf); } else { - buf[0]=0; + barr = (*env)->NewByteArray(env, 0); } - //TODO find a way for creating Strings from encodings other than UTF-8 - //On Linux, UTF8 is fine since this is the default platform encoding. - //Other platforms may be problematic since accessing Java classes - //(for Converters) doesnt work through the OSGi classloaders. - linkTarget = (*env)->NewStringUTF(env, buf); + linkTarget = getString(env, barr); setSymlinkInFileInfo(env, fileInfo, linkTarget); //stat link target (will fail for broken links) Index: src/org/eclipse/core/filesystem/IFileStore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/IFileStore.java,v retrieving revision 1.21 diff -u -r1.21 IFileStore.java --- src/org/eclipse/core/filesystem/IFileStore.java 29 Jan 2007 23:21:08 -0000 1.21 +++ src/org/eclipse/core/filesystem/IFileStore.java 30 Jan 2007 12:25:13 -0000 @@ -394,8 +394,9 @@ * The {@link EFS#SET_ATTRIBUTES} update flag controls * whether the file's attributes are changed. When this flag is specified, * the EFS#ATTRIBUTE_* values, with - * the exception of EFS#ATTRIBUTE_DIRECTORY - * and EFS#ATTRIBUTE_SYMLINK, + * the exception of EFS#ATTRIBUTE_DIRECTORY, + * EFS#ATTRIBUTE_SYMLINK and + * EFS#ATTRIBUTE_LINK_TARGET, * are set for this file. When this flag is not specified, changed attributes * on the provided file info are ignored. *

Index: src/org/eclipse/core/filesystem/IFileInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/IFileInfo.java,v retrieving revision 1.15 diff -u -r1.15 IFileInfo.java --- src/org/eclipse/core/filesystem/IFileInfo.java 29 Jan 2007 23:21:08 -0000 1.15 +++ src/org/eclipse/core/filesystem/IFileInfo.java 30 Jan 2007 12:25:13 -0000 @@ -52,14 +52,14 @@ public abstract boolean getAttribute(int attribute); /** - * Returns the value of the specified attribute for this file. The attribute + * Returns the value of the specified attribute for this file. The attribute * must be one of the EFS#ATTRIBUTE_* * constants. Returns null if this file does not exist, * could not be accessed, or the provided attribute does not apply to this * file system. * * @param attribute The kind of attribute to return. Currently only - * {@link EFS_ATTRIBUTE_LINK_TARGET} is supported. + * {@link EFS#ATTRIBUTE_LINK_TARGET} is supported. * @return the value of the extended String attribute for this file. * @see IFileSystem#attributes() * @since org.eclipse.core.filesystem 1.1 Index: src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java,v retrieving revision 1.11 diff -u -r1.11 LocalFileSystem.java --- src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java 29 Jan 2007 23:21:08 -0000 1.11 +++ src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java 30 Jan 2007 12:25:13 -0000 @@ -82,15 +82,16 @@ if (!LocalFileNatives.usingNatives()) return attributes; - //all known platforms support the read only flag + //all known platforms with native implementation support the read only flag attributes |= EFS.ATTRIBUTE_READ_ONLY; + //this must be kept in sync with the actual native implementations. String os = getOS(); if (os.equals(Platform.OS_WIN32)) attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN; else if (os.equals(Platform.OS_LINUX)) - attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK; - else if (os.equals(Platform.OS_MACOSX)) + attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET; + else if (os.equals(Platform.OS_MACOSX) || os.equals(Platform.OS_HPUX) || os.equals(Platform.OS_QNX)) attributes |= EFS.ATTRIBUTE_EXECUTABLE; return attributes; } Index: src/org/eclipse/core/internal/filesystem/local/Convert.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/Convert.java,v retrieving revision 1.3 diff -u -r1.3 Convert.java --- src/org/eclipse/core/internal/filesystem/local/Convert.java 21 Nov 2006 18:43:10 -0000 1.3 +++ src/org/eclipse/core/internal/filesystem/local/Convert.java 30 Jan 2007 12:25:13 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API *******************************************************************************/ package org.eclipse.core.internal.filesystem.local; @@ -69,6 +70,26 @@ } /** + * Calling new String(byte[] s) creates a new encoding object and other garbage. + * This can be avoided by calling new String(byte[] s, String encoding) instead. + * @param source String in platform bytes + * @return converted Java String + * @since org.eclipse.core.filesystem 1.1 + */ + public static String fromPlatformBytes(byte[] source) { + if (defaultEncoding == null) + return new String(source); + // try to use the default encoding + try { + return new String(source, defaultEncoding); + } catch (UnsupportedEncodingException e) { + // null the default encoding so we don't try it again + defaultEncoding = null; + return new String(source); + } + } + + /** * Calling String.getBytes() creates a new encoding object and other garbage. * This can be avoided by calling String.getBytes(String encoding) instead. */ Index: src/org/eclipse/core/filesystem/provider/FileInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/provider/FileInfo.java,v retrieving revision 1.9 diff -u -r1.9 FileInfo.java --- src/org/eclipse/core/filesystem/provider/FileInfo.java 29 Jan 2007 23:21:08 -0000 1.9 +++ src/org/eclipse/core/filesystem/provider/FileInfo.java 30 Jan 2007 12:25:13 -0000 @@ -229,6 +229,8 @@ /** * Sets or clears a String attribute, e.g. symbolic link target. * + * @param attribute The kind of attribute to set. Currently only + * {@link EFS#ATTRIBUTE_LINK_TARGET} is supported. * @param value The String attribute, or null to clear * the attribute * @since org.eclipse.core.filesystem 1.1