diff options
author | valerijf <valerijf@yahoo-inc.com> | 2017-03-13 09:27:30 +0100 |
---|---|---|
committer | valerijf <valerijf@yahoo-inc.com> | 2017-03-13 09:27:30 +0100 |
commit | 92569b7ce5502ea337a9eb029e4510f702816c2c (patch) | |
tree | 40ed291bc3a61132026ff777934bdedd986373e0 /node-maintainer | |
parent | 8d4c358fbdffe099ca3c164f156286563c2aa59b (diff) |
Do not follow symbolic links when getting last modified time
Diffstat (limited to 'node-maintainer')
-rw-r--r-- | node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java | 5 | ||||
-rw-r--r-- | node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java index b9255ace848..7ad2d4c4d66 100644 --- a/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java +++ b/node-maintainer/src/main/java/com/yahoo/vespa/hosted/node/maintainer/FileHelper.java @@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.node.maintainer; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.LinkOption; import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.attribute.FileTime; @@ -164,9 +165,9 @@ public class FileHelper { } } - private static FileTime getLastModifiedTime(Path path) { + static FileTime getLastModifiedTime(Path path) { try { - return Files.getLastModifiedTime(path); + return Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS); } catch (IOException e) { throw new RuntimeException("Failed to get last modified time of " + path.toAbsolutePath(), e); } diff --git a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java index 55057cd83f9..5cc3c0280df 100644 --- a/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java +++ b/node-maintainer/src/test/java/com/yahoo/vespa/hosted/node/maintainer/FileHelperTest.java @@ -245,6 +245,19 @@ public class FileHelperTest { assertTrue(subSubFolder2.toFile().isDirectory()); } + @Test + public void testDoesNotFailOnLastModifiedOnSymLink() throws IOException { + Path symPath = folder.getRoot().toPath().resolve("symlink"); + Path fakePath = Paths.get("/some/not/existant/file"); + + Files.createSymbolicLink(symPath, fakePath); + assertTrue(Files.isSymbolicLink(symPath)); + assertFalse(Files.exists(fakePath)); + + // Not possible to set modified time on symlink in java, so just check that it doesn't crash + FileHelper.getLastModifiedTime(symPath).toInstant(); + } + private void initSubDirectories() throws IOException { File subFolder1 = folder.newFolder("test_folder1"); File subFolder2 = folder.newFolder("test_folder2"); |