diff --git a/modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java b/modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java index 7c64162bbe2..2b96f0fc15f 100644 --- a/modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java +++ b/modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java @@ -618,15 +618,15 @@ public DirectoryStreamB newDirectoryStream(FsInode dir) th @Override public void remove(String path) throws ChimeraFsException { - FsInode inode = path2inode(path); - FsInode parent = this.getParentOf(inode); - if (parent == null) { + File filePath = new File(path); + + String parentPath = filePath.getParent(); + if (parentPath == null) { throw new ChimeraFsException("Cannot delete file system root."); } - File filePath = new File(path); + FsInode parent = path2inode(parentPath); String name = filePath.getName(); - this.remove(parent, name); } diff --git a/modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java b/modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java index c864f9f0d3c..0ca6066bdfa 100644 --- a/modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java +++ b/modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java @@ -327,6 +327,28 @@ public void testRemoveLinkToDir() throws Exception { _fs.createLink(base, "aLink", "/junit"); } + @Test + public void testRemoveLinkToSomewhare() throws Exception { + + FsInode linkBase = _rootInode.mkdir("links"); + + _fs.createLink(linkBase, "file123", 0, 0, 0644, "/files/file123".getBytes(Charsets.UTF_8)); + _fs.remove("/links/file123"); + } + + @Test + public void testRemoveLinkToFile() throws Exception { + + FsInode fileBase = _rootInode.mkdir("files"); + FsInode linkBase = _rootInode.mkdir("links"); + FsInode fileInode = fileBase.create("file123", 0, 0, 0644); + + _fs.createLink(linkBase, "file123", 0, 0, 0644, "/files/file123".getBytes(Charsets.UTF_8)); + _fs.remove("/links/file123"); + + assertTrue("original file is gone!", fileInode.exists()); + } + @Ignore("broken test, normal filesystems do not allow directory hard-links. Why does chimera?") @Test public void testDirHardLink() throws Exception {