IDEA-118477 (optimization: root path is directory)

This commit is contained in:
Roman Shevchenko
2014-01-08 17:51:27 +01:00
parent 7eb1c2bb33
commit 54ea61c9af
3 changed files with 24 additions and 4 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap
if (index >= 0) rootPath = rootPath.substring(0, index);
File rootFile = new File(FileUtil.toSystemDependentName(rootPath));
if (index > 0 || !rootFile.isDirectory()) {
if (index > 0 || !(FileUtil.isRootPath(rootFile) || rootFile.isDirectory())) {
File parentFile = rootFile.getParentFile();
if (parentFile == null) {
throw new FileNotFoundException(rootPath);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1458,4 +1458,12 @@ public class FileUtil extends FileUtilRt {
return map;
}
public static boolean isRootPath(@NotNull File file) {
return isRootPath(file.getPath());
}
public static boolean isRootPath(@NotNull String path) {
return path.equals("/") || path.matches("[a-zA-Z]:[/\\\\]");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -156,4 +156,16 @@ public class FileUtilLightTest {
Map<String, String> map = FileUtil.loadProperties(new StringReader(data));
assertEquals(ContainerUtil.newArrayList("key2", "key1", "key3"), ContainerUtil.newArrayList(map.keySet()));
}
@Test
public void testRootPath() {
assertTrue(FileUtil.isRootPath("/"));
assertTrue(FileUtil.isRootPath("c:/"));
assertTrue(FileUtil.isRootPath("Z:\\"));
assertFalse(FileUtil.isRootPath(""));
assertFalse(FileUtil.isRootPath("/tmp"));
assertFalse(FileUtil.isRootPath("c:"));
assertFalse(FileUtil.isRootPath("X:\\Temp"));
}
}