Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 290201 | Differences between
and this patch

Collapse All | Expand All

(-)natives/macosx/Makefile (-3 / +2 lines)
Lines 1-5 Link Here
1
#**********************************************************************
1
#**********************************************************************
2
# Copyright (c) 2000, 2005 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 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 15-19 Link Here
15
	cc -I /System/Library/Frameworks/JavaVM.framework/Headers localfile.c -o $(LIB_NAME) -bundle -framework JavaVM -framework CoreServices
15
	cc -I /System/Library/Frameworks/JavaVM.framework/Headers localfile.c -o $(LIB_NAME) -bundle -framework JavaVM -framework CoreServices
16
16
17
clean:
17
clean:
18
	rm *.o
18
	rm *.jnilib
19
	
(-)natives/macosx/localfile.c (-2 / +51 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 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 23-28 Link Here
23
23
24
#define USE_IMMUTABLE_FLAG 1
24
#define USE_IMMUTABLE_FLAG 1
25
#define USE_ARCHIVE_FLAG 0
25
#define USE_ARCHIVE_FLAG 0
26
#define EFS_SYMLINK_SUPPORT 1
26
27
27
/*
28
/*
28
 * Get a null-terminated byte array from a java char array.
29
 * Get a null-terminated byte array from a java char array.
Lines 120-125 Link Here
120
	return JNI_TRUE;
121
	return JNI_TRUE;
121
}
122
}
122
123
124
#if defined(EFS_SYMLINK_SUPPORT)
125
/*
126
 * Set symbolic link information in IFileInfo 
127
 */
128
jboolean setSymlinkInFileInfo (JNIEnv *env, jobject fileInfo, jstring linkTarget) {
129
    jclass cls;
130
    jmethodID mid;
131
132
    cls = (*env)->GetObjectClass(env, fileInfo);
133
    if (cls == 0) return JNI_FALSE;
134
135
    // set symlink attribute
136
    mid = (*env)->GetMethodID(env, cls, "setAttribute", "(IZ)V");
137
    if (mid == 0) return JNI_FALSE;
138
    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_SYMLINK, JNI_TRUE);
139
140
    // set link target
141
    mid = (*env)->GetMethodID(env, cls, "setStringAttribute", "(ILjava/lang/String;)V");
142
    if (mid == 0) return JNI_FALSE;
143
    (*env)->CallVoidMethod(env, fileInfo, mid, ATTRIBUTE_LINK_TARGET, linkTarget);
144
145
    return JNI_TRUE;
146
}
147
#endif
148
123
/*
149
/*
124
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
150
 * Class:     org_eclipse_core_internal_filesystem_local_LocalFileNatives
125
 * Method:    internalGetFileInfo
151
 * Method:    internalGetFileInfo
Lines 141-155 Link Here
141
167
142
	struct stat info;
168
	struct stat info;
143
	jint code;
169
	jint code;
170
	jstring linkTarget = NULL;
144
171
145
	/* get stat */
172
	/* get stat */
146
	char *name= (char*) getUTF8ByteArray(env, target);
173
	char *name= (char*) getUTF8ByteArray(env, target);
174
#if defined(EFS_SYMLINK_SUPPORT)
175
	//do an lstat first to see if it is a symbolic link
176
	code = lstat(name, &info);
177
	if (code == 0 && (info.st_mode & S_IFLNK) == S_IFLNK) {
178
		//symbolic link: read link target
179
		char buf[PATH_MAX+1];
180
		int len;
181
		len = readlink((const char*)name, buf, PATH_MAX);
182
		if (len>0) {
183
			buf[len]=0;
184
		} else {
185
			buf[0]=0;
186
		}
187
		// Mac OS encodes symlink target using UTF-8, ignoring platform default
188
		linkTarget = (*env)->NewStringUTF(env, buf);
189
		setSymlinkInFileInfo(env, fileInfo, linkTarget);
190
191
		//stat link target (will fail for broken links)
192
		code = stat((const char*)name, &info);
193
	}
194
#else
147
	code = stat(name, &info);
195
	code = stat(name, &info);
196
#endif
148
	free(name);
197
	free(name);
149
198
150
	/* test if an error occurred */
199
	/* test if an error occurred */
151
	if (code == -1)
200
	if (code == -1)
152
	  return 0;
201
	  return JNI_FALSE;
153
	return convertStatToFileInfo(env, info, fileInfo);
202
	return convertStatToFileInfo(env, info, fileInfo);
154
}
203
}
155
204
(-)src/org/eclipse/core/internal/filesystem/local/LocalFileSystem.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 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 101-107 Link Here
101
		else if (os.equals(Constants.OS_LINUX) || (os.equals(Constants.OS_SOLARIS) && arch.equals(Constants.ARCH_SPARC)))
101
		else if (os.equals(Constants.OS_LINUX) || (os.equals(Constants.OS_SOLARIS) && arch.equals(Constants.ARCH_SPARC)))
102
			attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
102
			attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
103
		else if (os.equals(Constants.OS_MACOSX) || os.equals(Constants.OS_HPUX) || os.equals(Constants.OS_QNX))
103
		else if (os.equals(Constants.OS_MACOSX) || os.equals(Constants.OS_HPUX) || os.equals(Constants.OS_QNX))
104
			attributes |= EFS.ATTRIBUTE_EXECUTABLE;
104
			attributes |= EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
105
		return attributes;
105
		return attributes;
106
	}
106
	}
107
107
(-)src/org/eclipse/core/tests/filesystem/SymlinkTest.java (-9 / +71 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
2
 * Copyright (c) 2007, 2009 Wind River Systems, Inc. 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 14-20 Link Here
14
 *******************************************************************************/
14
 *******************************************************************************/
15
package org.eclipse.core.tests.filesystem;
15
package org.eclipse.core.tests.filesystem;
16
16
17
import java.io.*;
17
import java.io.OutputStream;
18
import org.eclipse.core.filesystem.*;
18
import org.eclipse.core.filesystem.*;
19
import org.eclipse.core.resources.IWorkspace;
19
import org.eclipse.core.resources.IWorkspace;
20
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.resources.ResourcesPlugin;
Lines 48-55 Link Here
48
	public static boolean isTestablePlatform() {
48
	public static boolean isTestablePlatform() {
49
		// A Platform is testable if it supports the "ln -s" command.
49
		// A Platform is testable if it supports the "ln -s" command.
50
		String os = Platform.getOS();
50
		String os = Platform.getOS();
51
		//currently we only support linux and solaris
51
		//currently we only support linux, solaris and mac os
52
		if (os.equals(Platform.OS_LINUX) || os.equals(Platform.OS_SOLARIS)
52
		if (os.equals(Platform.OS_LINUX) || os.equals(Platform.OS_SOLARIS) || os.equals(Platform.OS_MACOSX)
53
		//		  ||os.equals(Platform.OS_AIX)
53
		//		  ||os.equals(Platform.OS_AIX)
54
		//		  ||os.equals(Platform.OS_HPUX)
54
		//		  ||os.equals(Platform.OS_HPUX)
55
		//		  ||isWindowsVista()
55
		//		  ||isWindowsVista()
Lines 295-301 Link Here
295
	public void testSymlinkEnabled() {
295
	public void testSymlinkEnabled() {
296
		String os = Platform.getOS();
296
		String os = Platform.getOS();
297
		String arch = Platform.getOSArch();
297
		String arch = Platform.getOSArch();
298
		if (Platform.OS_LINUX.equals(os) || (Platform.OS_SOLARIS.equals(os) && Platform.ARCH_SPARC.equals(arch))) {
298
		if (Platform.OS_LINUX.equals(os) || (Platform.OS_SOLARIS.equals(os) && Platform.ARCH_SPARC.equals(arch)) || Platform.OS_MACOSX.equals(os)) {
299
			assertTrue(haveSymlinks());
299
			assertTrue(haveSymlinks());
300
		} else {
300
		} else {
301
			assertFalse(haveSymlinks());
301
			assertFalse(haveSymlinks());
Lines 332-361 Link Here
332
		}
332
		}
333
	}
333
	}
334
334
335
	public void testSymlinkPutInfo() throws Exception {
335
	public void testSymlinkPutLastModified() throws Exception {
336
		if (!isTestablePlatform()) {
336
		if (!isTestablePlatform()) {
337
			return;
337
			return;
338
		}
338
		}
339
		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
340
			// flag EFS.SET_LAST_MODIFIED is set by java.io and it fails on Mac OS
341
			return;
342
		}
339
		//check that putInfo() "writes through" the symlink
343
		//check that putInfo() "writes through" the symlink
340
		makeLinkStructure();
344
		makeLinkStructure();
341
		long oldTime = iFile.getLastModified();
345
		long oldTime = iFile.getLastModified();
342
		long timeToSet = oldTime - 100000;
346
		long timeToSet = oldTime - 100000;
343
		illFile.setLastModified(timeToSet);
347
		illFile.setLastModified(timeToSet);
344
		illFile.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
345
		llFile.putInfo(illFile, EFS.SET_ATTRIBUTES | EFS.SET_LAST_MODIFIED, getMonitor());
348
		llFile.putInfo(illFile, EFS.SET_ATTRIBUTES | EFS.SET_LAST_MODIFIED, getMonitor());
346
		iFile = aFile.fetchInfo();
349
		iFile = aFile.fetchInfo();
347
		assertEquals(iFile.getLastModified(), timeToSet);
350
		assertEquals(iFile.getLastModified(), timeToSet);
348
		assertTrue(iFile.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
349
351
350
		oldTime = iDir.getLastModified();
352
		oldTime = iDir.getLastModified();
351
		timeToSet = oldTime - 100000;
353
		timeToSet = oldTime - 100000;
352
		illDir.setLastModified(timeToSet);
354
		illDir.setLastModified(timeToSet);
353
		illDir.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
354
		llDir.putInfo(illDir, EFS.SET_ATTRIBUTES | EFS.SET_LAST_MODIFIED, getMonitor());
355
		llDir.putInfo(illDir, EFS.SET_ATTRIBUTES | EFS.SET_LAST_MODIFIED, getMonitor());
355
		iDir = aDir.fetchInfo();
356
		iDir = aDir.fetchInfo();
356
		assertTrue(iDir.getLastModified() != oldTime);
357
		assertTrue(iDir.getLastModified() != oldTime);
357
		assertEquals(iDir.getLastModified(), timeToSet);
358
		assertEquals(iDir.getLastModified(), timeToSet);
359
		if (haveSymlinks()) {
360
			//check that link properties are maintained even through putInfo
361
			illFile = llFile.fetchInfo();
362
			illDir = llDir.fetchInfo();
363
			assertTrue(illFile.getAttribute(EFS.ATTRIBUTE_SYMLINK));
364
			assertTrue(illDir.getAttribute(EFS.ATTRIBUTE_SYMLINK));
365
			assertEquals(illFile.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET), "lFile");
366
			assertEquals(illDir.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET), "lDir");
367
		}
368
	}
369
370
	public void testSymlinkPutReadOnly() throws Exception {
371
		if (!isTestablePlatform()) {
372
			return;
373
		}
374
		//check that putInfo() "writes through" the symlink
375
		makeLinkStructure();
376
		illFile.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
377
		llFile.putInfo(illFile, EFS.SET_ATTRIBUTES, getMonitor());
378
		iFile = aFile.fetchInfo();
379
		assertTrue(iFile.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
380
381
		illFile.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
382
		llFile.putInfo(illFile, EFS.SET_ATTRIBUTES, getMonitor());
383
		iFile = aFile.fetchInfo();
384
		assertFalse(iFile.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
385
386
		illDir.setAttribute(EFS.ATTRIBUTE_READ_ONLY, true);
387
		llDir.putInfo(illDir, EFS.SET_ATTRIBUTES, getMonitor());
388
		iDir = aDir.fetchInfo();
358
		assertTrue(iDir.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
389
		assertTrue(iDir.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
390
391
		illDir.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
392
		llDir.putInfo(illDir, EFS.SET_ATTRIBUTES, getMonitor());
393
		iDir = aDir.fetchInfo();
394
		assertFalse(iDir.getAttribute(EFS.ATTRIBUTE_READ_ONLY));
395
		if (haveSymlinks()) {
396
			//check that link properties are maintained even through putInfo
397
			illFile = llFile.fetchInfo();
398
			illDir = llDir.fetchInfo();
399
			assertTrue(illFile.getAttribute(EFS.ATTRIBUTE_SYMLINK));
400
			assertTrue(illDir.getAttribute(EFS.ATTRIBUTE_SYMLINK));
401
			assertEquals(illFile.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET), "lFile");
402
			assertEquals(illDir.getStringAttribute(EFS.ATTRIBUTE_LINK_TARGET), "lDir");
403
		}
404
	}
405
406
	public void testSymlinkPutExecutable() throws Exception {
407
		if (!isTestablePlatform()) {
408
			return;
409
		}
410
		//check that putInfo() "writes through" the symlink
411
		makeLinkStructure();
412
		illFile.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, true);
413
		llFile.putInfo(illFile, EFS.SET_ATTRIBUTES, getMonitor());
414
		iFile = aFile.fetchInfo();
415
		assertTrue(iFile.getAttribute(EFS.ATTRIBUTE_EXECUTABLE));
416
417
		illDir.setAttribute(EFS.ATTRIBUTE_EXECUTABLE, false);
418
		llDir.putInfo(illDir, EFS.SET_ATTRIBUTES, getMonitor());
419
		iDir = aDir.fetchInfo();
420
		assertFalse(iDir.getAttribute(EFS.ATTRIBUTE_EXECUTABLE));
359
		if (haveSymlinks()) {
421
		if (haveSymlinks()) {
360
			//check that link properties are maintained even through putInfo
422
			//check that link properties are maintained even through putInfo
361
			illFile = llFile.fetchInfo();
423
			illFile = llFile.fetchInfo();

Return to bug 290201