Skip to content

Commit

Permalink
Fix invalid attributes of symlinks
Browse files Browse the repository at this point in the history
This invalid size cause weird handling of symbolic links on some tools (ie: tar)
  • Loading branch information
Toilal committed Jan 22, 2019
1 parent fbbb6ea commit 092b391
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/world/gfi/nfs4j/fs/AbstractNioFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ public Inode parentOf(Inode inode) throws IOException {
@Override
public String readlink(Inode inode) throws IOException {
Path path = handleRegistry.toPath(inode);
return this.readlinkFromPath(path);
}

protected String readlinkFromPath(Path path) throws IOException {
String linkData = Files.readSymbolicLink(path).normalize().toString();
if (File.separatorChar != '/') {
linkData = linkData.replace(File.separatorChar, '/');
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/world/gfi/nfs4j/fs/WindowsNioFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,17 @@ protected DosFileAttributes getFileAttributes(Path path) throws IOException {
protected void applyFileAttributesToStat(Stat stat, Path path, DosFileAttributes attrs) throws IOException {
super.applyFileAttributesToStat(stat, path, attrs);
stat.setNlink(1);

if (Files.isSymbolicLink(path)) {
this.applySymbolicLinkAttributesToStat(stat, path, attrs);
}
}

/**
* To be consistent with a native filesystem, Symbolic links size should match the content of the link.
*/
protected void applySymbolicLinkAttributesToStat(Stat stat, Path path, DosFileAttributes attrs) throws IOException {
String linkData = this.readlinkFromPath(path);
stat.setSize(linkData.length());
}
}

0 comments on commit 092b391

Please sign in to comment.