예제 #1
0
  @Test
  public void getParentTest() throws InvalidPathException {
    // get a parent that is non-root
    Assert.assertEquals("/foo", PathUtils.getParent("/foo/bar"));
    Assert.assertEquals("/foo", PathUtils.getParent("/foo/bar/"));
    Assert.assertEquals("/foo", PathUtils.getParent("/foo/./bar/"));
    Assert.assertEquals("/foo", PathUtils.getParent("/foo/././bar/"));

    // get a parent that is root
    Assert.assertEquals("/", PathUtils.getParent("/foo"));
    Assert.assertEquals("/", PathUtils.getParent("/foo/bar/../"));
    Assert.assertEquals("/", PathUtils.getParent("/foo/../bar/"));

    // get parent of root
    Assert.assertEquals("/", PathUtils.getParent("/"));
    Assert.assertEquals("/", PathUtils.getParent("/foo/bar/../../"));
    Assert.assertEquals("/", PathUtils.getParent("/foo/../bar/../"));
  }
예제 #2
0
파일: FileUtils.java 프로젝트: rhli/tachyon
 /**
  * Creates the local block path and all the parent directories. Also, sets the appropriate
  * permissions.
  *
  * @param path The path of the block.
  * @throws IOException when fails to create block path and parent directories with appropriate
  *     permissions.
  */
 public static void createBlockPath(String path) throws IOException {
   try {
     createStorageDirPath(PathUtils.getParent(path));
   } catch (InvalidPathException e) {
     throw new IOException("Failed to create block path, get parent path of " + path + "failed");
   } catch (IOException ioe) {
     throw new IOException("Failed to create block path " + path);
   }
 }
예제 #3
0
 /** Test of relativizeFolders method, of class PathUtils. */
 public void testGetParent() {
   System.out.println("testGetParent");
   Path result = PathUtils.getParent(Paths.get(""));
   assertEquals(Paths.get(""), result);
   result = PathUtils.getParent(Paths.get("import.lesscache"));
   assertEquals(Paths.get(""), result);
   result = PathUtils.getParent(Paths.get("path/import.lesscache"));
   assertEquals(Paths.get("path"), result);
   result = PathUtils.getParent(Paths.get("base/path/import.lesscache"));
   assertEquals(Paths.get("base/path"), result);
   result = PathUtils.getParent(Paths.get("../file.lesscache"));
   assertEquals(Paths.get(".."), result);
   result = PathUtils.getParent(Paths.get("../../file.lesscache"));
   assertEquals(Paths.get("../.."), result);
   result = PathUtils.getParent(Paths.get("../other/file.lesscache"));
   assertEquals(Paths.get("../other"), result);
 }