From 092b391f79a32e7b35c3ce3334da48d2db0db467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Tue, 22 Jan 2019 12:37:19 +0100 Subject: [PATCH] Fix invalid attributes of symlinks This invalid size cause weird handling of symbolic links on some tools (ie: tar) --- .../world/gfi/nfs4j/fs/AbstractNioFileSystem.java | 4 ++++ .../world/gfi/nfs4j/fs/WindowsNioFileSystem.java | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/java/world/gfi/nfs4j/fs/AbstractNioFileSystem.java b/src/main/java/world/gfi/nfs4j/fs/AbstractNioFileSystem.java index d9f80ef..9bd5836 100644 --- a/src/main/java/world/gfi/nfs4j/fs/AbstractNioFileSystem.java +++ b/src/main/java/world/gfi/nfs4j/fs/AbstractNioFileSystem.java @@ -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, '/'); diff --git a/src/main/java/world/gfi/nfs4j/fs/WindowsNioFileSystem.java b/src/main/java/world/gfi/nfs4j/fs/WindowsNioFileSystem.java index 91d3375..8f56ade 100644 --- a/src/main/java/world/gfi/nfs4j/fs/WindowsNioFileSystem.java +++ b/src/main/java/world/gfi/nfs4j/fs/WindowsNioFileSystem.java @@ -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()); } }