Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 57750 Details for
Bug 170317
API: Add symbolic links to EFS / IFileInfo APIs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Changed to getStringAttribute(int), and setStringAttribute(int, String)
patch.txt (text/plain), 16.61 KB, created by
John Arthorne
on 2007-01-29 18:01:45 EST
(
hide
)
Description:
Changed to getStringAttribute(int), and setStringAttribute(int, String)
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2007-01-29 18:01:45 EST
Size:
16.61 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.filesystem >Index: natives/localfile.h >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/natives/localfile.h,v >retrieving revision 1.3 >diff -u -r1.3 localfile.h >--- natives/localfile.h 12 Oct 2005 20:27:58 -0000 1.3 >+++ natives/localfile.h 29 Jan 2007 23:02:57 -0000 >@@ -1,9 +1,13 @@ > /* >- * 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 > * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API > */ > /* DO NOT EDIT THIS FILE - it is machine generated */ > #include <jni.h> >@@ -15,7 +19,7 @@ > extern "C" { > #endif > >-//values from IFileStoreConstants >+//values from EFS > #undef ATTRIBUTE_DIRECTORY > #define ATTRIBUTE_DIRECTORY 0x01l > #undef ATTRIBUTE_READ_ONLY >@@ -26,6 +30,10 @@ > #define ATTRIBUTE_ARCHIVE 0x08l > #undef ATTRIBUTE_HIDDEN > #define ATTRIBUTE_HIDDEN 0x10l >+#undef ATTRIBUTE_SYMLINK >+#define ATTRIBUTE_SYMLINK 0x20l >+#undef ATTRIBUTE_LINK_TARGET >+#define ATTRIBUTE_LINK_TARGET 0x40l > #undef SET_ATTRIBUTES > #define SET_ATTRIBUTES 0x01l > #undef SET_LAST_MODIFIED >Index: src/org/eclipse/core/filesystem/EFS.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/src/org/eclipse/core/filesystem/EFS.java,v >retrieving revision 1.13 >diff -u -r1.13 EFS.java >--- src/org/eclipse/core/filesystem/EFS.java 9 Nov 2006 22:16:49 -0000 1.13 >+++ src/org/eclipse/core/filesystem/EFS.java 29 Jan 2007 23:02:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 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.filesystem; > >@@ -146,6 +147,65 @@ > public static final int ATTRIBUTE_HIDDEN = 1 << 4; > > /** >+ * Attribute constant (value 1 <<5) indicating that a >+ * file is a symbolic link. >+ * </p> >+ * <p> >+ * If this attribute is <code>true</code> for a given {@link IFileInfo} >+ * instance, a String value may be associated with the attribute >+ * holding the symbolic link target. This link target can be >+ * retrieved with {@link IFileInfo#getStringAttribute(int)} with attribute >+ * type {@link #ATTRIBUTE_LINK_TARGET}. >+ * </p> >+ * <p> >+ * Symbolic links are handled transparently, as implemented by the >+ * underlying operating system. This means, that all other attributes >+ * of a {@link IFileInfo} apply to the link target instead of the link. >+ * Reading or writing a file, or changing attributes applies to the >+ * link target and not the link itself. In case a symbolic link points >+ * to another symbolic link, the chain of links is transparently followed >+ * and operations apply to the actual file or directory being referenced >+ * by the chain of symbolic links. >+ * </p> >+ * <p> >+ * Broken symbolic links (which do not reference any valid file or directory) >+ * are being returned by {link {@link IFileStore#childInfos(int, IProgressMonitor)}, >+ * but {link {@link IFileInfo#exists()} returns <code>false</code> for these. >+ * Operations like reading or writing on broken symbolic links throw >+ * a "file not found" exception. >+ * </p> >+ * <p> >+ * The only operation that does not transparently work on the link target, >+ * is deletion: {@link IFileStore#delete(int, IProgressMonitor)} >+ * deletes the symbolic link but not the link target. >+ * >+ * @see IFileStore#fetchInfo() >+ * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor) >+ * @see IFileInfo#getAttribute(int) >+ * @see IFileInfo#setAttribute(int, boolean) >+ * @since org.eclipse.core.filesystem 1.1 >+ */ >+ public static final int ATTRIBUTE_SYMLINK = 1 << 5; >+ >+ /** >+ * Attribute constant (value 1 <<6) for a string attribute indicating the >+ * target file name of a symbolic link. >+ * </p> >+ * <p> >+ * Note that setting the link target attribute does not cause a symbolic >+ * link to be created, or changed to link to a different file. Rather, this >+ * attribute is set by file system implementations based on the current >+ * state of a link. >+ * </p> >+ * >+ * @see IFileInfo#getStringAttribute(int) >+ * @see FileInfo#setStringAttribute(int, String) >+ * @see #ATTRIBUTE_SYMLINK >+ * @since org.eclipse.core.filesystem 1.1 >+ */ >+ public static final int ATTRIBUTE_LINK_TARGET = 1 << 6; >+ >+ /** > * Scheme constant (value "file") indicating the local file system scheme. > * @see EFS#getLocalFileSystem() > */ >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.20 >diff -u -r1.20 IFileStore.java >--- src/org/eclipse/core/filesystem/IFileStore.java 9 Nov 2006 21:00:19 -0000 1.20 >+++ src/org/eclipse/core/filesystem/IFileStore.java 29 Jan 2007 23:02:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 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.filesystem; > >@@ -394,6 +395,7 @@ > * whether the file's attributes are changed. When this flag is specified, > * the <code>EFS#ATTRIBUTE_*</code> values, with > * the exception of <code>EFS#ATTRIBUTE_DIRECTORY</code> >+ * and <code>EFS#ATTRIBUTE_SYMLINK</code>, > * are set for this file. When this flag is not specified, changed attributes > * on the provided file info are ignored. > * </p> >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.14 >diff -u -r1.14 IFileInfo.java >--- src/org/eclipse/core/filesystem/IFileInfo.java 9 Nov 2006 22:16:49 -0000 1.14 >+++ src/org/eclipse/core/filesystem/IFileInfo.java 29 Jan 2007 23:02:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 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.filesystem; > >@@ -51,6 +52,21 @@ > public abstract boolean getAttribute(int attribute); > > /** >+ * Returns the value of the specified attribute for this file. The attribute >+ * must be one of the <code>EFS#ATTRIBUTE_*</code> >+ * constants. Returns <code>null</code> 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. >+ * @return the value of the extended String attribute for this file. >+ * @see IFileSystem#attributes() >+ * @since org.eclipse.core.filesystem 1.1 >+ */ >+ public abstract String getStringAttribute(int attribute); >+ >+ /** > * Returns the last modified time for this file, or {@link EFS#NONE} > * if the file does not exist or the last modified time could not be computed. > * <p> >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.10 >diff -u -r1.10 LocalFileSystem.java >--- src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java 19 Dec 2006 22:18:35 -0000 1.10 >+++ src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java 29 Jan 2007 23:02:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 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; > >@@ -87,7 +88,9 @@ > String os = getOS(); > if (os.equals(Platform.OS_WIN32)) > attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN; >- else if (os.equals(Platform.OS_LINUX) || os.equals(Platform.OS_MACOSX)) >+ 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; > return attributes; > } >Index: natives/unix/localfile.c >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.filesystem/natives/unix/localfile.c,v >retrieving revision 1.4 >diff -u -r1.4 localfile.c >--- natives/unix/localfile.c 12 Oct 2005 20:26:34 -0000 1.4 >+++ natives/unix/localfile.c 29 Jan 2007 23:02:57 -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 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Red Hat Incorporated - get/setResourceAttribute code >+ * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API > *******************************************************************************/ > #include <jni.h> > #include <sys/types.h> >@@ -17,6 +18,10 @@ > #include <string.h> > #include "../localfile.h" > #include <os_custom.h> >+#ifdef LINUX >+#include <limits.h> >+#include <unistd.h> >+#endif > > /* > * Get a null-terminated byte array from a java byte array. >@@ -94,15 +99,32 @@ > (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_EXECUTABLE, JNI_TRUE); > } > >- // sym link? >-// if ((info.st_mode & S_IFLNK) == S_IFLNK) { >-// mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V"); >-// if (mid == 0) return JNI_FALSE; >-// (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK, JNI_TRUE); >-// } > return JNI_TRUE; > } > >+#ifdef LINUX >+/* >+ * Set symbolic link information in IFileInfo >+ */ >+jboolean setSymlinkInFileInfo (JNIEnv *env, jobject fileInfo, jstring linkTarget) { >+ jclass cls; >+ jmethodID mid; >+ >+ cls = (*env)->GetObjectClass(env, fileInfo); >+ if (cls == 0) return JNI_FALSE; >+ >+ // set symlink attribute >+ mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V"); >+ if (mid == 0) return JNI_FALSE; >+ (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_SYMLINK, JNI_TRUE); >+ >+ // set link target >+ mid = (*env)->GetMethodID(env, cls, "setStringAttribute", "(ILjava/lang/String;)V"); >+ if (mid == 0) return JNI_FALSE; >+ (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK_TARGET, linkTarget); >+} >+#endif >+ > /* > * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives > * Method: internalGetFileInfo >@@ -114,10 +136,36 @@ > jlong result; > jint code; > jbyte *name; >+ jstring linkTarget = NULL; > > /* get stat */ > name = getByteArray(env, target); >+#ifdef LINUX >+ //do an lstat first to see if it is a symbolic link >+ code = lstat((const char*)name, &info); >+ if (code == 0 && (info.st_mode & S_IFLNK) == S_IFLNK) { >+ //symbolic link: read link target >+ char buf[PATH_MAX+1]; >+ int len; >+ len = readlink((const char*)name, buf, PATH_MAX); >+ if (len>0) { >+ buf[len]=0; >+ } else { >+ buf[0]=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); >+ setSymlinkInFileInfo(env, fileInfo, linkTarget); >+ >+ //stat link target (will fail for broken links) >+ code = stat((const char*)name, &info); >+ } >+#else > code = stat((const char*)name, &info); >+#endif > free(name); > > /* test if an error occurred */ >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.8 >diff -u -r1.8 FileInfo.java >--- src/org/eclipse/core/filesystem/provider/FileInfo.java 9 Nov 2006 22:16:49 -0000 1.8 >+++ src/org/eclipse/core/filesystem/provider/FileInfo.java 29 Jan 2007 23:02:57 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 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.filesystem.provider; > >@@ -17,7 +18,7 @@ > * This class should be used by file system providers in their implementation > * of API methods that return {@link IFileInfo} objects. > * <p> >- * This class is not intended to be subclassed. >+ * This class is not intended to be subclassed by clients. > * </p> > * @since org.eclipse.core.filesystem 1.0 > */ >@@ -53,6 +54,11 @@ > private String name = ""; //$NON-NLS-1$ > > /** >+ * The target file name if this is a symbolic link >+ */ >+ private String linkTarget = null; >+ >+ /** > * Creates a new file information object with default values. > */ > public FileInfo() { >@@ -112,6 +118,15 @@ > } > > /* (non-Javadoc) >+ * @see org.eclipse.core.filesystem.IFileInfo#getStringAttribute(int) >+ */ >+ public String getStringAttribute(int attribute) { >+ if (attribute == EFS.ATTRIBUTE_LINK_TARGET) >+ return this.linkTarget; >+ return null; >+ } >+ >+ /* (non-Javadoc) > * @see org.eclipse.core.filesystem.IFileInfo#lastModified() > */ > public long getLastModified() { >@@ -212,6 +227,18 @@ > } > > /** >+ * Sets or clears a String attribute, e.g. symbolic link target. >+ * >+ * @param value The String attribute, or <code>null</code> to clear >+ * the attribute >+ * @since org.eclipse.core.filesystem 1.1 >+ */ >+ public void setStringAttribute(int attribute, String value) { >+ if (attribute == EFS.ATTRIBUTE_LINK_TARGET) >+ this.linkTarget = value; >+ } >+ >+ /** > * For debugging purposes only. > */ > public String toString() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 170317
:
56827
|
56828
|
57518
|
57703
|
57737
| 57750 |
57792