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
  • Loading branch information
kofemann committed Nov 28, 2013
1 parent e99720f commit b1c04d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/chimera/src/main/java/org/dcache/chimera/JdbcFs.java
Expand Up @@ -618,15 +618,15 @@ public DirectoryStreamB<HimeraDirectoryEntry> 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);
}

Expand Down
22 changes: 22 additions & 0 deletions modules/chimera/src/test/java/org/dcache/chimera/BasicTest.java
Expand Up @@ -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 {
Expand Down

0 comments on commit b1c04d4

Please sign in to comment.