View | Details | Raw Unified | Return to bug 170317 | Differences between
and this patch

Collapse All | Expand All

(-)natives/localfile.h (-2 / +10 lines)
Lines 1-9 Link Here
1
/*
1
/*
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
7
 */
11
 */
8
/* DO NOT EDIT THIS FILE - it is machine generated */
12
/* DO NOT EDIT THIS FILE - it is machine generated */
9
#include <jni.h>
13
#include <jni.h>
Lines 15-21 Link Here
15
extern "C" {
19
extern "C" {
16
#endif
20
#endif
17
21
18
//values from IFileStoreConstants
22
//values from EFS
19
#undef ATTRIBUTE_DIRECTORY
23
#undef ATTRIBUTE_DIRECTORY
20
#define ATTRIBUTE_DIRECTORY 0x01l
24
#define ATTRIBUTE_DIRECTORY 0x01l
21
#undef ATTRIBUTE_READ_ONLY
25
#undef ATTRIBUTE_READ_ONLY
Lines 26-31 Link Here
26
#define ATTRIBUTE_ARCHIVE 0x08l
30
#define ATTRIBUTE_ARCHIVE 0x08l
27
#undef ATTRIBUTE_HIDDEN
31
#undef ATTRIBUTE_HIDDEN
28
#define ATTRIBUTE_HIDDEN 0x10l
32
#define ATTRIBUTE_HIDDEN 0x10l
33
#undef ATTRIBUTE_SYMLINK
34
#define ATTRIBUTE_SYMLINK 0x20l
35
#undef ATTRIBUTE_LINK_TARGET
36
#define ATTRIBUTE_LINK_TARGET 0x40l
29
#undef SET_ATTRIBUTES
37
#undef SET_ATTRIBUTES
30
#define SET_ATTRIBUTES 0x01l
38
#define SET_ATTRIBUTES 0x01l
31
#undef SET_LAST_MODIFIED
39
#undef SET_LAST_MODIFIED
(-)src/org/eclipse/core/filesystem/EFS.java (-1 / +61 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.filesystem;
12
package org.eclipse.core.filesystem;
12
13
Lines 146-151 Link Here
146
	public static final int ATTRIBUTE_HIDDEN = 1 << 4;
147
	public static final int ATTRIBUTE_HIDDEN = 1 << 4;
147
148
148
	/**
149
	/**
150
	 * Attribute constant (value 1 &lt;&lt;5) indicating that a
151
	 * file is a symbolic link.
152
	 * </p>
153
	 * <p>
154
	 * If this attribute is <code>true</code> for a given {@link IFileInfo}
155
	 * instance, a String value may be associated with the attribute
156
	 * holding the symbolic link target. This link target can be
157
	 * retrieved with {@link IFileInfo#getStringAttribute(int)} with attribute
158
	 * type {@link #ATTRIBUTE_LINK_TARGET}.
159
	 * </p>
160
	 * <p>
161
	 * Symbolic links are handled transparently, as implemented by the 
162
	 * underlying operating system. This means, that all other attributes
163
	 * of a {@link IFileInfo} apply to the link target instead of the link.
164
	 * Reading or writing a file, or changing attributes applies to the
165
	 * link target and not the link itself. In case a symbolic link points
166
	 * to another symbolic link, the chain of links is transparently followed
167
	 * and operations apply to the actual file or directory being referenced
168
	 * by the chain of symbolic links.
169
	 * </p>
170
	 * <p>
171
	 * Broken symbolic links (which do not reference any valid file or directory)
172
	 * are being returned by {link {@link IFileStore#childInfos(int, IProgressMonitor)},
173
	 * but {link {@link IFileInfo#exists()} returns <code>false</code> for these.
174
	 * Operations like reading or writing on broken symbolic links throw 
175
	 * a "file not found" exception.  
176
	 * </p>
177
	 * <p>
178
	 * The only operation that does not transparently work on the link target,
179
	 * is deletion: {@link IFileStore#delete(int, IProgressMonitor)}
180
	 * deletes the symbolic link but not the link target. 
181
	 * 
182
	 * @see IFileStore#fetchInfo()
183
	 * @see IFileStore#putInfo(IFileInfo, int, IProgressMonitor)
184
	 * @see IFileInfo#getAttribute(int)
185
	 * @see IFileInfo#setAttribute(int, boolean)
186
	 * @since org.eclipse.core.filesystem 1.1
187
	 */
188
	public static final int ATTRIBUTE_SYMLINK = 1 << 5;
189
190
	/**
191
	 * Attribute constant (value 1 &lt;&lt;6) for a string attribute indicating the
192
	 * target file name of a symbolic link.
193
	 * </p>
194
	 * <p>
195
	 * Note that setting the link target attribute does not cause a symbolic
196
	 * link to be created, or changed to link to a different file.  Rather, this
197
	 * attribute is set by file system implementations based on the current
198
	 * state of a link.
199
	 * </p>
200
	 * 
201
	 * @see IFileInfo#getStringAttribute(int)
202
	 * @see FileInfo#setStringAttribute(int, String)
203
	 * @see #ATTRIBUTE_SYMLINK
204
	 * @since org.eclipse.core.filesystem 1.1
205
	 */
206
	public static final int ATTRIBUTE_LINK_TARGET = 1 << 6;
207
	
208
	/**
149
	 * Scheme constant (value "file") indicating the local file system scheme.
209
	 * Scheme constant (value "file") indicating the local file system scheme.
150
	 * @see EFS#getLocalFileSystem()
210
	 * @see EFS#getLocalFileSystem()
151
	 */
211
	 */
(-)src/org/eclipse/core/filesystem/IFileStore.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.filesystem;
12
package org.eclipse.core.filesystem;
12
13
Lines 394-399 Link Here
394
	 * whether the file's attributes are changed.  When this flag is specified,
395
	 * whether the file's attributes are changed.  When this flag is specified,
395
	 * the <code>EFS#ATTRIBUTE_*</code> values, with
396
	 * the <code>EFS#ATTRIBUTE_*</code> values, with
396
	 * the exception of <code>EFS#ATTRIBUTE_DIRECTORY</code>
397
	 * the exception of <code>EFS#ATTRIBUTE_DIRECTORY</code>
398
	 * and <code>EFS#ATTRIBUTE_SYMLINK</code>,
397
	 * are set for this file. When this flag is not specified, changed attributes
399
	 * are set for this file. When this flag is not specified, changed attributes
398
	 * on the provided file info are ignored.
400
	 * on the provided file info are ignored.
399
	 * </p>
401
	 * </p>
(-)src/org/eclipse/core/filesystem/IFileInfo.java (-1 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.filesystem;
12
package org.eclipse.core.filesystem;
12
13
Lines 51-56 Link Here
51
	public abstract boolean getAttribute(int attribute);
52
	public abstract boolean getAttribute(int attribute);
52
53
53
	/**
54
	/**
55
	* Returns the value of the specified attribute for this file.  The attribute
56
	 * must be one of the <code>EFS#ATTRIBUTE_*</code>
57
	 * constants. Returns <code>null</code> if this file does not exist,
58
	 * could not be accessed, or the provided attribute does not apply to this
59
	 * file system.	 
60
	 * 
61
	 * @param attribute The kind of attribute to return.  Currently only
62
	 * {@link EFS_ATTRIBUTE_LINK_TARGET} is supported.
63
	 * @return the value of the extended String attribute for this file.
64
	 * @see IFileSystem#attributes()
65
	 * @since org.eclipse.core.filesystem 1.1
66
	 */
67
	public abstract String getStringAttribute(int attribute);
68
69
	/**
54
	 * Returns the last modified time for this file, or {@link EFS#NONE}
70
	 * Returns the last modified time for this file, or {@link EFS#NONE}
55
	 * if the file does not exist or the last modified time could not be computed.
71
	 * if the file does not exist or the last modified time could not be computed.
56
	 * <p>
72
	 * <p>
(-)src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java (-2 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.filesystem.local;
12
package org.eclipse.core.internal.filesystem.local;
12
13
Lines 87-93 Link Here
87
		String os = getOS();
88
		String os = getOS();
88
		if (os.equals(Platform.OS_WIN32))
89
		if (os.equals(Platform.OS_WIN32))
89
			attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN;
90
			attributes |= EFS.ATTRIBUTE_ARCHIVE | EFS.ATTRIBUTE_HIDDEN;
90
		else if (os.equals(Platform.OS_LINUX) || os.equals(Platform.OS_MACOSX))
91
		else if (os.equals(Platform.OS_LINUX))
92
			attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK;
93
		else if (os.equals(Platform.OS_MACOSX))
91
			attributes |= EFS.ATTRIBUTE_EXECUTABLE;
94
			attributes |= EFS.ATTRIBUTE_EXECUTABLE;
92
		return attributes;
95
		return attributes;
93
	}
96
	}
(-)natives/unix/localfile.c (-7 / +55 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Red Hat Incorporated - get/setResourceAttribute code
10
 *     Red Hat Incorporated - get/setResourceAttribute code
11
 *     Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
11
 *******************************************************************************/
12
 *******************************************************************************/
12
#include <jni.h>
13
#include <jni.h>
13
#include <sys/types.h>
14
#include <sys/types.h>
Lines 17-22 Link Here
17
#include <string.h>
18
#include <string.h>
18
#include "../localfile.h"
19
#include "../localfile.h"
19
#include <os_custom.h>
20
#include <os_custom.h>
21
#ifdef LINUX
22
#include <limits.h>
23
#include <unistd.h>
24
#endif
20
25
21
/*
26
/*
22
 * Get a null-terminated byte array from a java byte array.
27
 * Get a null-terminated byte array from a java byte array.
Lines 94-108 Link Here
94
	    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_EXECUTABLE, JNI_TRUE);
99
	    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_EXECUTABLE, JNI_TRUE);
95
    }
100
    }
96
101
97
	// sym link?
98
//    if ((info.st_mode & S_IFLNK) == S_IFLNK) {
99
//	    mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
100
//	    if (mid == 0) return JNI_FALSE;
101
//	    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK, JNI_TRUE);
102
//    }
103
	return JNI_TRUE;
102
	return JNI_TRUE;
104
}
103
}
105
104
105
#ifdef LINUX
106
/*
107
 * Set symbolic link information in IFileInfo 
108
 */
109
jboolean setSymlinkInFileInfo (JNIEnv *env, jobject fileInfo, jstring linkTarget) {
110
    jclass cls;
111
    jmethodID mid;
112
113
    cls = (*env)->GetObjectClass(env, fileInfo);
114
    if (cls == 0) return JNI_FALSE;
115
116
    // set symlink attribute
117
    mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
118
    if (mid == 0) return JNI_FALSE;
119
    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_SYMLINK, JNI_TRUE);
120
    
121
    // set link target
122
    mid = (*env)->GetMethodID(env, cls, "setStringAttribute", "(ILjava/lang/String;)V");
123
    if (mid == 0) return JNI_FALSE;
124
    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK_TARGET, linkTarget);
125
}
126
#endif
127
106
/*
128
/*
107
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
129
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
108
 * Method:    internalGetFileInfo
130
 * Method:    internalGetFileInfo
Lines 114-123 Link Here
114
	jlong result;
136
	jlong result;
115
	jint code;
137
	jint code;
116
	jbyte *name;
138
	jbyte *name;
139
	jstring linkTarget = NULL;
117
140
118
	/* get stat */
141
	/* get stat */
119
	name = getByteArray(env, target);
142
	name = getByteArray(env, target);
143
#ifdef LINUX
144
	//do an lstat first to see if it is a symbolic link
145
	code = lstat((const char*)name, &info);
146
	if (code == 0 && (info.st_mode & S_IFLNK) == S_IFLNK) {
147
		//symbolic link: read link target
148
		char buf[PATH_MAX+1];
149
		int len;
150
		len = readlink((const char*)name, buf, PATH_MAX);
151
		if (len>0) {
152
			buf[len]=0;
153
		} else {
154
			buf[0]=0;
155
		}
156
		//TODO find a way for creating Strings from encodings other than UTF-8
157
		//On Linux, UTF8 is fine since this is the default platform encoding.
158
		//Other platforms may be problematic since accessing Java classes
159
		//(for Converters) doesnt work through the OSGi classloaders.
160
		linkTarget = (*env)->NewStringUTF(env, buf);
161
		setSymlinkInFileInfo(env, fileInfo, linkTarget);
162
163
		//stat link target (will fail for broken links)
164
		code = stat((const char*)name, &info);
165
	}
166
#else
120
	code = stat((const char*)name, &info);
167
	code = stat((const char*)name, &info);
168
#endif
121
	free(name);
169
	free(name);
122
170
123
	/* test if an error occurred */
171
	/* test if an error occurred */
(-)src/org/eclipse/core/filesystem/provider/FileInfo.java (-2 / +29 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 * Martin Oberhuber (Wind River) - [170317] add symbolic link support to API
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.filesystem.provider;
12
package org.eclipse.core.filesystem.provider;
12
13
Lines 17-23 Link Here
17
 * This class should be used by file system providers in their implementation
18
 * This class should be used by file system providers in their implementation
18
 * of API methods that return {@link IFileInfo} objects.
19
 * of API methods that return {@link IFileInfo} objects.
19
 * <p>
20
 * <p>
20
 * This class is not intended to be subclassed.
21
 * This class is not intended to be subclassed by clients.
21
 * </p>
22
 * </p>
22
 * @since org.eclipse.core.filesystem 1.0
23
 * @since org.eclipse.core.filesystem 1.0
23
 */
24
 */
Lines 53-58 Link Here
53
	private String name = ""; //$NON-NLS-1$
54
	private String name = ""; //$NON-NLS-1$
54
55
55
	/**
56
	/**
57
	 * The target file name if this is a symbolic link
58
	 */
59
	private String linkTarget = null; 
60
61
	/**
56
	 * Creates a new file information object with default values.
62
	 * Creates a new file information object with default values.
57
	 */
63
	 */
58
	public FileInfo() {
64
	public FileInfo() {
Lines 112-117 Link Here
112
	}
118
	}
113
119
114
	/* (non-Javadoc)
120
	/* (non-Javadoc)
121
	 * @see org.eclipse.core.filesystem.IFileInfo#getStringAttribute(int)
122
	 */
123
	public String getStringAttribute(int attribute) {
124
		if (attribute == EFS.ATTRIBUTE_LINK_TARGET)
125
			return this.linkTarget;
126
		return null;
127
	}
128
129
	/* (non-Javadoc)
115
	 * @see org.eclipse.core.filesystem.IFileInfo#lastModified()
130
	 * @see org.eclipse.core.filesystem.IFileInfo#lastModified()
116
	 */
131
	 */
117
	public long getLastModified() {
132
	public long getLastModified() {
Lines 212-217 Link Here
212
	}
227
	}
213
228
214
	/**
229
	/**
230
	 * Sets or clears a String attribute, e.g. symbolic link target.
231
	 * 
232
	 * @param value The String attribute, or <code>null</code> to clear
233
	 * the attribute
234
	 * @since org.eclipse.core.filesystem 1.1
235
	 */
236
	public void setStringAttribute(int attribute, String value) {
237
		if (attribute == EFS.ATTRIBUTE_LINK_TARGET)
238
			this.linkTarget = value;
239
	}
240
241
	/**
215
	 * For debugging purposes only.
242
	 * For debugging purposes only.
216
	 */
243
	 */
217
	public String toString() {
244
	public String toString() {

Return to bug 170317