Bug 338010. Fixed three tests failing on Mac.

Change-Id: I4c3641ec0e602c7f89edca62ae3b7f14dc23c49b
Signed-off-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
diff --git a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
index f327862..bdd1640 100644
--- a/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
+++ b/bundles/org.eclipse.core.filesystem/src/org/eclipse/core/internal/filesystem/local/unix/UnixFileNatives.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2012 IBM Corporation and others.
+ * Copyright (c) 2010, 2015 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,10 +7,11 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Sergey Prigogin (Google) - [338010] Resource.createLink() does not preserve symbolic links
  *******************************************************************************/
 package org.eclipse.core.internal.filesystem.local.unix;
 
-import java.io.UnsupportedEncodingException;
+import java.io.*;
 import java.util.Enumeration;
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileInfo;
@@ -92,6 +93,31 @@
 			if (getErrno() != ENOENT)
 				info.setError(IFileInfo.IO_ERROR);
 		}
+
+		// Fill in the real name of the file.
+		File file = new File(fileName);
+		final String lastName = file.getName();
+		// If the file does not exist, or the file system is not case sensitive, or the name
+		// of the file is not case sensitive, use the name we have. Otherwise obtain the real
+		// name of the file from a parent directory listing.
+		if (!info.exists() || EFS.getLocalFileSystem().isCaseSensitive() ||
+				lastName.toLowerCase().equals(lastName.toUpperCase())) {
+			info.setName(lastName);
+		} else {
+			// Notice that file.getParentFile() is guaranteed to be not null since fileName == "/"
+			// case is handled by the other branch of the 'if' statement.
+			String[] names = file.getParentFile().list(new FilenameFilter() {
+				public boolean accept(File dir, String n) {
+					return n.equalsIgnoreCase(lastName);
+				}
+			});
+			if (names.length == 1) {
+				info.setName(names[0]);
+			} else {
+				info.setName(lastName);
+			}
+		}
+
 		return info;
 	}
 
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
index 960bc90..90aafa7 100644
--- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
+++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/WorkspaceTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -44,7 +44,13 @@
 	 * @throws Exception
 	 */
 	public void doCleanup() throws Exception {
+		IPath location = getWorkspace().getRoot().getLocation().append("testProject");
+		deleteOnTearDown(location);
+		IPath location2 = getWorkspace().getRoot().getLocation().append("testProject2");
+		deleteOnTearDown(location2);
 		cleanup();
+		assertTrue(location.toOSString() + " has not been deleted", !location.toFile().exists());
+		assertTrue(location2.toOSString() + " has not been deleted", !location2.toFile().exists());
 	}
 
 	/**