Browse Source

Let FS_Win32_Cygwin detect symlink support by creating temporary symlink

The class FS_Win32 was always trying out to create a temporary symlink
in order to find out whether symlinks are supported. FS_Win32_Cygwin was
overwriting this method and always returned true. But when the user
running JGit does not have administrative rights then the creation of
symlinks is forbidden even if he is running on FS_Win32_Cygwin. A lot of
tests failed only on the Windows platform because of this. It was
correctly detected that FS_Win32_Cygwin is the filesystem abstraction to
be used but creation of symlinks always failed because of lacking
privileges of the user running the tests.

This fix teaches FS_Win32_Cygwin to behave like FS_Win32 and to test
whether symlinks can be created in order to find out whether symlinks
are supported.

Change-Id: Ie2394631ffc4c489bd37c3ec142ed44bbfcac726
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.2.0.201601211800-r
Christian Halstrick 8 years ago
parent
commit
18af2d4265

+ 6
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java View File

@@ -79,6 +79,7 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Assume;
import org.junit.Test;

public class DirCacheCheckoutTest extends RepositoryTestCase {
@@ -925,6 +926,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {

@Test
public void testCheckoutChangeLinkToEmptyDir() throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "was_file";
Git git = Git.wrap(db);

@@ -961,6 +963,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {

@Test
public void testCheckoutChangeLinkToEmptyDirs() throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "was_file";
Git git = Git.wrap(db);

@@ -999,6 +1002,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {

@Test
public void testCheckoutChangeLinkToNonEmptyDirs() throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file";
Git git = Git.wrap(db);

@@ -1043,6 +1047,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testCheckoutChangeLinkToNonEmptyDirsAndNewIndexEntry()
throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file";
Git git = Git.wrap(db);

@@ -1364,6 +1369,7 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
@Test
public void testOverwriteUntrackedLinkModeChange()
throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file.txt";
Git git = Git.wrap(db);


+ 2
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorJava7Test.java View File

@@ -67,6 +67,7 @@ import org.junit.Test;
public class FileTreeIteratorJava7Test extends RepositoryTestCase {
@Test
public void testFileModeSymLinkIsNotATree() throws IOException {
org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
FS fs = db.getFS();
// mål = target in swedish, just to get som unicode in here
writeTrashFile("mål/data", "targetdata");
@@ -163,6 +164,7 @@ public class FileTreeIteratorJava7Test extends RepositoryTestCase {
*/
@Test
public void testSymlinkActuallyModified() throws Exception {
org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
final String NORMALIZED = "target";
final byte[] NORMALIZED_BYTES = Constants.encode(NORMALIZED);
try (ObjectInserter oi = db.newObjectInserter()) {

+ 1
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java View File

@@ -55,6 +55,7 @@ import org.junit.Test;
public class TreeWalkJava7Test extends RepositoryTestCase {
@Test
public void testSymlinkToDirNotRecursingViaSymlink() throws Exception {
org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
FS fs = db.getFS();
assertTrue(fs.supportsSymlinks());
writeTrashFile("target/data", "targetdata");

+ 2
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSJava7Test.java View File

@@ -57,6 +57,7 @@ import java.util.Set;

import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

@@ -87,6 +88,7 @@ public class FSJava7Test {
*/
@Test
public void testSymlinkAttributes() throws IOException, InterruptedException {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
FS fs = FS.DETECTED;
File link = new File(trash, "ä");
File target = new File(trash, "å");

+ 1
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtils7Test.java View File

@@ -73,6 +73,7 @@ public class FileUtils7Test {
@Test
public void testDeleteSymlinkToDirectoryDoesNotDeleteTarget()
throws IOException {
org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
FS fs = FS.DETECTED;
File dir = new File(trash, "dir");
File file = new File(dir, "file");

+ 0
- 5
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java View File

@@ -162,11 +162,6 @@ public class FS_Win32_Cygwin extends FS_Win32 {
errRedirect, stdinArgs);
}

@Override
public boolean supportsSymlinks() {
return true;
}

/**
* @since 3.7
*/

Loading…
Cancel
Save