diff options
author | Harald Musum <musum@yahooinc.com> | 2022-10-28 13:49:36 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2022-10-28 13:49:36 +0200 |
commit | 6beb3433c4598a9836e8ac3288f55d92097bd627 (patch) | |
tree | 3ab0ba953bf35c79af3b9df32c24e160b5829f55 /configserver | |
parent | d092241882ffbcee42d707ac364a39221bbe3990 (diff) |
Better error handling if both schemas/ and searchdefintions/ exist
If something fails when having both directories, throw an
InvalidApplicationException with an explanation about what to do
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java index 89ca0265008..49678c5e385 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionRepository.java @@ -841,15 +841,24 @@ public class SessionRepository { File schemasDir = applicationDir.resolve(ApplicationPackage.SCHEMAS_DIR.getRelative()).toFile(); File sdDir = applicationDir.resolve(ApplicationPackage.SEARCH_DEFINITIONS_DIR.getRelative()).toFile(); if (sdDir.exists() && sdDir.isDirectory()) { - File[] sdFiles = sdDir.listFiles(); - if (sdFiles != null) { - Files.createDirectories(schemasDir.toPath()); - Arrays.asList(sdFiles).forEach(file -> Exceptions.uncheck( - () -> Files.move(file.toPath(), - schemasDir.toPath().resolve(file.toPath().getFileName()), - StandardCopyOption.REPLACE_EXISTING))); + try { + File[] sdFiles = sdDir.listFiles(); + if (sdFiles != null) { + Files.createDirectories(schemasDir.toPath()); + Arrays.asList(sdFiles).forEach(file -> Exceptions.uncheck( + () -> Files.move(file.toPath(), + schemasDir.toPath().resolve(file.toPath().getFileName()), + StandardCopyOption.REPLACE_EXISTING))); + } + Files.delete(sdDir.toPath()); + } catch (IOException | UncheckedIOException e) { + if (schemasDir.exists() && schemasDir.isDirectory()) + throw new InvalidApplicationException( + "Both " + ApplicationPackage.SCHEMAS_DIR.getRelative() + " and " + ApplicationPackage.SEARCH_DEFINITIONS_DIR + + " exists in application package, please remove " + ApplicationPackage.SEARCH_DEFINITIONS_DIR, e); + else + throw e; } - Files.delete(sdDir.toPath()); } } |