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>
This commit is contained in:
Christian Halstrick 2015-11-20 14:33:15 +01:00 committed by Matthias Sohn
parent 0353b1d3ff
commit 18af2d4265
6 changed files with 12 additions and 5 deletions

View File

@ -79,6 +79,7 @@
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 void testCheckoutOutChanges() throws IOException {
@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 void testCheckoutChangeLinkToEmptyDir() throws Exception {
@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 void testCheckoutChangeLinkToEmptyDirs() throws Exception {
@Test
public void testCheckoutChangeLinkToNonEmptyDirs() throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file";
Git git = Git.wrap(db);
@ -1043,6 +1047,7 @@ public void testCheckoutChangeLinkToNonEmptyDirs() throws Exception {
@Test
public void testCheckoutChangeLinkToNonEmptyDirsAndNewIndexEntry()
throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file";
Git git = Git.wrap(db);
@ -1364,6 +1369,7 @@ public void testOverwriteUntrackedFileModeChange()
@Test
public void testOverwriteUntrackedLinkModeChange()
throws Exception {
Assume.assumeTrue(FS.DETECTED.supportsSymlinks());
String fname = "file.txt";
Git git = Git.wrap(db);

View File

@ -67,6 +67,7 @@
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 void apply(DirCacheEntry ent) {
*/
@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()) {

View File

@ -55,6 +55,7 @@
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");

View File

@ -57,6 +57,7 @@
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 void tearDown() throws Exception {
*/
@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, "å");

View File

@ -73,6 +73,7 @@ public void tearDown() throws Exception {
@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");

View File

@ -162,11 +162,6 @@ public ProcessResult runHookIfPresent(Repository repository, String hookName,
errRedirect, stdinArgs);
}
@Override
public boolean supportsSymlinks() {
return true;
}
/**
* @since 3.7
*/