diff options
author | Harald Musum <musum@yahooinc.com> | 2023-04-24 09:47:07 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-04-24 09:47:07 +0200 |
commit | 3e80ace7c106852bc2db634ff871905cfcae9428 (patch) | |
tree | edea7ed7deee3129fe56d675d0d3bc997f05c46c /configserver | |
parent | bc7e1b8c1a96a49838e55a7b97c4de565abc9ad3 (diff) |
Use Files.move/() to move file references
renameTo() is platform dependent and issue #26821 indicates that
it fails when using mounted volumes and Docker. Use Files.move() instead
and simplify accordingly
Diffstat (limited to 'configserver')
-rw-r--r-- | configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java index b9118602058..c9682060b25 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDirectory.java @@ -175,25 +175,20 @@ public class FileDirectory extends AbstractComponent { ensureRootExist(); Path tempDestinationDir = uncheck(() -> Files.createTempDirectory(root.toPath(), "writing")); try { - // Prepare and verify logfileInfo(source); - File destinationDir = destinationDir(reference); - File tempDestination = new File(tempDestinationDir.toFile(), source.getName()); - if ( ! destinationDir.mkdir()) - log.log(Level.WARNING, () -> "destination dir " + destinationDir + " already exists"); - // Copy files + // Copy files to temp dir + File tempDestination = new File(tempDestinationDir.toFile(), source.getName()); log.log(Level.FINE, () -> "Copying " + source.getAbsolutePath() + " to " + tempDestination.getAbsolutePath()); if (source.isDirectory()) IOUtils.copyDirectory(source, tempDestination, -1); else copyFile(source, tempDestination); - // Move to final destination - log.log(Level.FINE, () -> "Moving " + tempDestinationDir + " to " + destinationDir.getAbsolutePath()); - if ( ! tempDestinationDir.toFile().renameTo(destinationDir)) - log.log(Level.WARNING, "Failed moving '" + tempDestinationDir.toFile().getAbsolutePath() + - "' to '" + tempDestination.getAbsolutePath() + "'."); + // Move to destination dir + Path destinationDir = destinationDir(reference).toPath(); + log.log(Level.INFO, () -> "Moving " + tempDestinationDir + " to " + destinationDir); + Files.move(tempDestinationDir, destinationDir); return reference; } catch (IOException e) { throw new UncheckedIOException(e); |