Skip to content

Commit

Permalink
chimera: use path to get files parent on remove
Browse files Browse the repository at this point in the history
while in most of the cases we need to resolve symbolic links,
on delete we must only link and not the target

Acked-by: Gerd Behrmann
Target: master, 2.6, 2.7, 2.2
Require-book: no
Require-notes: no
(cherry picked from commit b1c04d4)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>

Conflicts:
	modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java
  • Loading branch information
kofemann committed Nov 28, 2013
1 parent 7bfaa67 commit aab574b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
11 changes: 6 additions & 5 deletions modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,14 @@ public DirectoryStreamB<HimeraDirectoryEntry> newDirectoryStream(FsInode dir) th
@Override
public boolean remove(String path) throws ChimeraFsException {

FsInode inode = path2inode(path);
FsInode parent = this.getParentOf(inode);
if (parent == null) {
return false;
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();

return this.remove(parent, name);
Expand Down
22 changes: 22 additions & 0 deletions modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ public void testRemoveLinkToDir() throws Exception {

}

@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 {
Expand Down

0 comments on commit aab574b

Please sign in to comment.