diff options
author | freva <valerijf@yahoo-inc.com> | 2017-01-06 16:05:13 +0100 |
---|---|---|
committer | freva <valerijf@yahoo-inc.com> | 2017-01-06 16:05:13 +0100 |
commit | f495c008acfad07a99a67259103933cc9cc730a6 (patch) | |
tree | e2c9c5accc39a09ec3305adeccc405730433e044 /node-admin | |
parent | 56faf25a6f550d82b39fb1e1c4b838c630e5c8bf (diff) |
Do not fail on invalid path
Diffstat (limited to 'node-admin')
2 files changed, 7 insertions, 11 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppData.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppData.java index 7315a52b7c8..ed3f3653fee 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppData.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppData.java @@ -14,7 +14,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; /** - * @author valerijf + * @author freva */ public class DeleteOldAppData { @@ -127,15 +127,11 @@ public class DeleteOldAppData { Files.deleteIfExists(file.toPath()); } - private static File[] getContentsOfDirectory(String directoryPath) { + static File[] getContentsOfDirectory(String directoryPath) { File directory = new File(directoryPath); File[] directoryContents = directory.listFiles(); - if (directoryContents == null) { - throw new IllegalArgumentException("The specified path is not a directory"); - } - - return directoryContents; + return directoryContents == null ? new File[0] : directoryContents; } private static File getMostRecentlyModifiedFileIn(File baseFile) { diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppDataTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppDataTest.java index 1affd51e68c..41a42095b1d 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppDataTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/maintenance/DeleteOldAppDataTest.java @@ -19,7 +19,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertTrue; /** - * @author valerijf + * @author freva */ public class DeleteOldAppDataTest { @Rule @@ -121,9 +121,9 @@ public class DeleteOldAppDataTest { assertThat(folder.getRoot().listFiles().length, is(8)); // 5 abc files + 1 week_old_file + 2 directories } - @Test(expected=IllegalArgumentException.class) - public void testDeleteWithInvalidBasePath() throws IOException { - DeleteOldAppData.deleteFiles("/some/made/up/dir/", 0, null, false); + @Test + public void testGetContentsOfNonExistingDirectory() throws IOException { + assertArrayEquals(new File[0], DeleteOldAppData.getContentsOfDirectory("/some/made/up/dir/")); } @Test(expected=IllegalArgumentException.class) |