diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java index d8ac54057138..53c50574e1ab 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/ex/temp/TempFileSystem.java @@ -245,6 +245,11 @@ public class TempFileSystem extends NewVirtualFileSystem { public String[] list() { return ArrayUtil.EMPTY_STRING_ARRAY; } + + @Override + public String toString() { + return getClass().getSimpleName() + ": " + myName; + } } private static class FSDir extends FSItem { diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java index 691f259047c4..ad0934eb4242 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java @@ -83,25 +83,12 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override public VirtualFile compute() { - VirtualFile root = getSourceRoot(); - if (path.length() == 0) return root; - String trimPath = StringUtil.trimStart(path, "/"); - final List dirs = StringUtil.split(trimPath, "/"); - for (String dirName : dirs) { - VirtualFile dir = root.findChild(dirName); - if (dir != null) { - root = dir; - } - else { - try { - root = root.createChildDirectory(this, dirName); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } + try { + return findOrCreateChildDir(getSourceRoot(), path); + } + catch (IOException e) { + throw new RuntimeException(e); } - return root; } }); } @@ -135,21 +122,32 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT } private VirtualFile findOrCreateChildDir(VirtualFile root, String relativePath) throws IOException { - String thisLevel = relativePath; - String nextLevel = null; - final int pos = relativePath.indexOf('/'); - if (pos > 0) { - thisLevel = relativePath.substring(0, pos); - nextLevel = relativePath.substring(pos+1); + if (relativePath.length() == 0) return root; + String trimPath = StringUtil.trimStart(relativePath, "/"); + final List dirs = StringUtil.split(trimPath, "/"); + for (String dirName : dirs) { + if (dirName.equals(".")) continue; + + if (dirName.equals("..")) { + root = root.getParent(); + if (root == null) throw new IllegalArgumentException("Invalid path: " + relativePath); + continue; + } + + VirtualFile dir = root.findChild(dirName); + if (dir != null) { + root = dir; + } + else { + try { + root = root.createChildDirectory(this, dirName); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } } - VirtualFile child = root.findChild(thisLevel); - if (child == null) { - child = root.createChildDirectory(this, thisLevel); - } - if (nextLevel != null && nextLevel.length() > 0) { - return findOrCreateChildDir(child, nextLevel); - } - return child; + return root; } @Override