This commit is contained in:
Roman Shevchenko
2012-09-28 17:25:47 +02:00
parent 0f0aa6f534
commit c428dda27f
3 changed files with 33 additions and 34 deletions
@@ -19,6 +19,7 @@ import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.IoTestUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -35,14 +36,14 @@ import java.util.Set;
import static com.intellij.openapi.util.io.FileUtil.createTempDirectory;
import static com.intellij.openapi.util.io.FileUtil.createTempFile;
import static com.intellij.openapi.util.io.IoTestUtil.createTempLink;
import static com.intellij.openapi.util.io.IoTestUtil.createSymLink;
import static com.intellij.testFramework.PlatformTestUtil.assertPathsEqual;
public class SymlinkHandlingTest extends SymlinkTestCase {
public void testMissingLink() throws Exception {
final File missingFile = new File(myTempDir, "missing_file");
assertTrue(missingFile.getPath(), !missingFile.exists() || missingFile.delete());
final File missingLinkFile = createTempLink(missingFile.getPath(), myTempDir.getPath() + "/missing_link");
final File missingLinkFile = createSymLink(missingFile.getPath(), myTempDir.getPath() + "/missing_link", false);
final VirtualFile missingLinkVFile = refreshAndFind(missingLinkFile);
assertNotNull(missingLinkVFile);
assertBrokenLink(missingLinkVFile);
@@ -51,7 +52,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testSelfLink() throws Exception {
String target = new File(myTempDir.getPath(), "self_link").getPath();
final File selfLinkFile = createTempLink(target, target);
final File selfLinkFile = createSymLink(target, target, false);
final VirtualFile selfLinkVFile = refreshAndFind(selfLinkFile);
assertNotNull(selfLinkVFile);
assertBrokenLink(selfLinkVFile);
@@ -59,7 +60,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
}
public void testDotLink() throws Exception {
final File dotLinkFile = createTempLink(".", myTempDir + "/dot_link");
final File dotLinkFile = IoTestUtil.createSymLink(".", myTempDir + "/dot_link");
final VirtualFile dotLinkVFile = refreshAndFind(dotLinkFile);
assertNotNull(dotLinkVFile);
assertTrue(dotLinkVFile.isSymLink());
@@ -70,7 +71,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testCircularLink() throws Exception {
final File upDir = createTempDirectory(myTempDir, "sub.", ".dir");
final File upLinkFile = createTempLink(upDir.getPath(), upDir.getPath() + "/up_link");
final File upLinkFile = IoTestUtil.createSymLink(upDir.getPath(), upDir.getPath() + "/up_link");
final VirtualFile upLinkVFile = refreshAndFind(upLinkFile);
assertNotNull(upLinkVFile);
assertTrue(upLinkVFile.isSymLink());
@@ -91,8 +92,8 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testMutualRecursiveLinks() throws Exception {
final File circularDir1 = createTempDirectory(myTempDir, "dir1.", ".tmp");
final File circularDir2 = createTempDirectory(myTempDir, "dir2.", ".tmp");
final File circularLink1 = createTempLink(circularDir2.getPath(), circularDir1 + "/link1");
final File circularLink2 = createTempLink(circularDir1.getPath(), circularDir2 + "/link2");
final File circularLink1 = IoTestUtil.createSymLink(circularDir2.getPath(), circularDir1 + "/link1");
final File circularLink2 = IoTestUtil.createSymLink(circularDir1.getPath(), circularDir2 + "/link2");
final VirtualFile circularLink1VFile = refreshAndFind(circularLink1);
final VirtualFile circularLink2VFile = refreshAndFind(circularLink2);
assertNotNull(circularLink1VFile);
@@ -103,14 +104,14 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testDuplicateLinks() throws Exception {
final File targetDir = createTempDirectory(myTempDir, "target.", ".dir");
final File link1 = createTempLink(targetDir.getPath(), myTempDir + "/link1");
final File link2 = createTempLink(targetDir.getPath(), myTempDir + "/link2");
final File link1 = IoTestUtil.createSymLink(targetDir.getPath(), myTempDir + "/link1");
final File link2 = IoTestUtil.createSymLink(targetDir.getPath(), myTempDir + "/link2");
assertVisitedPaths(targetDir.getPath(), link1.getPath(), link2.getPath());
}
public void testTargetIsWritable() throws Exception {
final File targetFile = createTempFile(myTempDir, "target.", ".txt");
final File linkFile = createTempLink(targetFile.getPath(), myTempDir + "/link");
final File linkFile = IoTestUtil.createSymLink(targetFile.getPath(), myTempDir + "/link");
final VirtualFile linkVFile = refreshAndFind(linkFile);
assertTrue("link=" + linkFile + ", vLink=" + linkVFile, linkVFile != null && !linkVFile.isDirectory() && linkVFile.isSymLink());
@@ -122,7 +123,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
assertFalse(linkVFile.getPath(), linkVFile.isWritable());
final File targetDir = createTempDirectory(myTempDir, "target.", ".dir");
final File linkDir = createTempLink(targetDir.getPath(), myTempDir + "/linkDir");
final File linkDir = IoTestUtil.createSymLink(targetDir.getPath(), myTempDir + "/linkDir");
final VirtualFile linkVDir = refreshAndFind(linkDir);
assertTrue("link=" + linkDir + ", vLink=" + linkVDir, linkVDir != null && linkVDir.isDirectory() && linkVDir.isSymLink());
@@ -146,7 +147,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testLinkDeleteIsSafe() throws Exception {
final File targetFile = createTempFile(myTempDir, "target", "");
final File linkFile = createTempLink(targetFile.getPath(), myTempDir + "/link");
final File linkFile = IoTestUtil.createSymLink(targetFile.getPath(), myTempDir + "/link");
final VirtualFile linkVFile = refreshAndFind(linkFile);
assertTrue("link=" + linkFile + ", vLink=" + linkVFile, linkVFile != null && !linkVFile.isDirectory() && linkVFile.isSymLink());
@@ -164,7 +165,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
final File targetDir = createTempDirectory(myTempDir, "targetDir", "");
final File childFile = new File(targetDir, "child.txt");
assertTrue(childFile.getPath(), childFile.exists() || childFile.createNewFile());
final File linkDir = createTempLink(targetDir.getPath(), myTempDir + "/linkDir");
final File linkDir = IoTestUtil.createSymLink(targetDir.getPath(), myTempDir + "/linkDir");
final VirtualFile linkVDir = refreshAndFind(linkDir);
assertTrue("link=" + linkDir + ", vLink=" + linkVDir,
linkVDir != null && linkVDir.isDirectory() && linkVDir.isSymLink() && linkVDir.getChildren().length == 1);
@@ -187,7 +188,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
final File targetDir = createTempDirectory(myTempDir, "targetDir", "");
// file link
File link = createTempLink(targetFile.getPath(), myTempDir + "/link");
File link = IoTestUtil.createSymLink(targetFile.getPath(), myTempDir + "/link");
VirtualFile vFile1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vFile1,
vFile1 != null && !vFile1.isDirectory() && vFile1.isSymLink());
@@ -200,7 +201,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
// dir => dir link
assertTrue(link.getPath(), link.delete());
link = createTempLink(targetDir.getPath(), myTempDir + "/link");
link = IoTestUtil.createSymLink(targetDir.getPath(), myTempDir + "/link");
vFile1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vFile1,
!vFile2.isValid() && vFile1 != null && vFile1.isDirectory() && vFile1.isSymLink());
@@ -213,7 +214,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
// file => file link
assertTrue(link.getPath(), link.delete());
link = createTempLink(targetFile.getPath(), myTempDir + "/link");
link = IoTestUtil.createSymLink(targetFile.getPath(), myTempDir + "/link");
vFile1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vFile1,
!vFile2.isValid() && vFile1 != null && !vFile1.isDirectory() && vFile1.isSymLink());
@@ -226,14 +227,14 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
assertTrue(new File(targetDir2, "child11.txt").createNewFile());
assertTrue(new File(targetDir2, "child12.txt").createNewFile());
final File link = createTempLink(targetDir1.getPath(), myTempDir + "/link");
final File link = IoTestUtil.createSymLink(targetDir1.getPath(), myTempDir + "/link");
final VirtualFile vLink1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vLink1,
vLink1 != null && vLink1.isDirectory() && vLink1.isSymLink());
assertEquals(1, vLink1.getChildren().length);
assertTrue(link.toString(), link.delete());
createTempLink(targetDir2.getPath(), myTempDir + "/" + link.getName());
IoTestUtil.createSymLink(targetDir2.getPath(), myTempDir + "/" + link.getName());
refresh();
assertFalse(vLink1.isValid());
@@ -249,14 +250,14 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
final File target2 = createTempFile(myTempDir, "target2.", ".txt");
FileUtil.writeToFile(target2, "some quite another text");
final File link = createTempLink(target1.getPath(), myTempDir + "/link");
final File link = IoTestUtil.createSymLink(target1.getPath(), myTempDir + "/link");
final VirtualFile vLink1 = refreshAndFind(link);
assertTrue("link=" + link + ", vLink=" + vLink1,
vLink1 != null && !vLink1.isDirectory() && vLink1.isSymLink());
assertEquals(FileUtil.loadFile(target1), VfsUtilCore.loadText(vLink1));
assertTrue(link.toString(), link.delete());
createTempLink(target2.getPath(), myTempDir + "/" + link.getName());
IoTestUtil.createSymLink(target2.getPath(), myTempDir + "/" + link.getName());
refresh();
assertFalse(vLink1.isValid());
@@ -313,7 +314,7 @@ public class SymlinkHandlingTest extends SymlinkTestCase {
public void testTraversePathBehindLink() throws Exception {
final File topDir = createTempDirectory(myTempDir, "top.", ".dir");
final File subDir1 = createTempDirectory(topDir, "sub1.", ".dir");
final File link = createTempLink(subDir1.getPath(), myTempDir + "/link");
final File link = IoTestUtil.createSymLink(subDir1.getPath(), myTempDir + "/link");
final VirtualFile vLink = refreshAndFind(link);
assertNotNull(link.getPath(), vLink);
@@ -137,7 +137,7 @@ public class FileAttributesReadingTest {
FileUtil.writeToFile(file, myTestData);
assertTrue(file.setLastModified(file.lastModified() - 5000));
assertTrue(file.setWritable(false, false));
final File link = IoTestUtil.createTempLink(file.getPath(), new File(myTempDirectory, "link").getPath());
final File link = IoTestUtil.createSymLink(file.getPath(), new File(myTempDirectory, "link").getPath());
final FileAttributes attributes = getAttributes(link);
assertEquals(FileAttributes.Type.FILE, attributes.type);
@@ -158,8 +158,8 @@ public class FileAttributesReadingTest {
FileUtil.writeToFile(file, myTestData);
assertTrue(file.setLastModified(file.lastModified() - 5000));
assertTrue(file.setWritable(false, false));
final File link1 = IoTestUtil.createTempLink(file.getPath(), new File(myTempDirectory, "link1").getPath());
final File link2 = IoTestUtil.createTempLink(link1.getPath(), new File(myTempDirectory, "link2").getPath());
final File link1 = IoTestUtil.createSymLink(file.getPath(), new File(myTempDirectory, "link1").getPath());
final File link2 = IoTestUtil.createSymLink(link1.getPath(), new File(myTempDirectory, "link2").getPath());
final FileAttributes attributes = getAttributes(link2);
assertEquals(FileAttributes.Type.FILE, attributes.type);
@@ -179,7 +179,7 @@ public class FileAttributesReadingTest {
final File file = FileUtil.createTempDirectory(myTempDirectory, "test.", ".tmp");
if (SystemInfo.isUnix) assertTrue(file.setWritable(false, false));
assertTrue(file.setLastModified(file.lastModified() - 5000));
final File link = IoTestUtil.createTempLink(file.getPath(), new File(myTempDirectory, "link").getPath());
final File link = IoTestUtil.createSymLink(file.getPath(), new File(myTempDirectory, "link").getPath());
final FileAttributes attributes = getAttributes(link);
assertEquals(FileAttributes.Type.DIRECTORY, attributes.type);
@@ -197,7 +197,7 @@ public class FileAttributesReadingTest {
assumeTrue(SystemInfo.areSymLinksSupported);
final File file = FileUtil.createTempFile(myTempDirectory, "test.", ".txt", false);
final File link = IoTestUtil.createTempLink(file.getPath(), new File(myTempDirectory, "link").getPath());
final File link = IoTestUtil.createSymLink(file.getPath(), new File(myTempDirectory, "link").getPath(), false);
final FileAttributes attributes = getAttributes(link);
assertNull(attributes.type);
@@ -213,7 +213,7 @@ public class FileAttributesReadingTest {
assumeTrue(SystemInfo.areSymLinksSupported);
final File dir = FileUtil.createTempDirectory(myTempDirectory, "test.", ".dir");
final File link = IoTestUtil.createTempLink(dir.getPath(), new File(dir, "link").getPath());
final File link = IoTestUtil.createSymLink(dir.getPath(), new File(dir, "link").getPath());
final FileAttributes attributes = getAttributes(link);
assertEquals(FileAttributes.Type.DIRECTORY, attributes.type);
@@ -32,8 +32,11 @@ import static org.junit.Assert.*;
public class IoTestUtil {
private IoTestUtil() { }
// todo[r.sh] use NIO2 API after migration to JDK 7
public static File createTempLink(@NotNull final String target, @NotNull final String link) throws InterruptedException, IOException {
public static File createSymLink(@NotNull String target, @NotNull String link) throws InterruptedException, IOException {
return createSymLink(target, link, true);
}
public static File createSymLink(@NotNull String target, @NotNull String link, boolean shouldExist) throws InterruptedException, IOException {
assertTrue(SystemInfo.isWindows || SystemInfo.isUnix);
final File targetFile = new File(FileUtil.toSystemDependentName(target));
@@ -51,7 +54,6 @@ public class IoTestUtil {
final int res = runCommand(command);
assertEquals(command.command().toString(), 0, res);
final boolean shouldExist = targetFile.exists() || SystemInfo.isWindows && SystemInfo.JAVA_VERSION.startsWith("1.6");
assertEquals("target=" + target + ", link=" + linkFile, shouldExist, linkFile.exists());
return linkFile;
}
@@ -222,10 +224,6 @@ public class IoTestUtil {
return dir;
}
public static File createTestFile(final String name) throws IOException {
return createTestFile(new File(FileUtil.getTempDirectory()), name);
}
public static File createTestFile(final File parent, final String name) throws IOException {
final File file = new File(parent, name);
assertTrue(file.getPath(), file.createNewFile());