From 3e80ace7c106852bc2db634ff871905cfcae9428 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 24 Apr 2023 09:47:07 +0200 Subject: 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 --- .../config/server/filedistribution/FileDirectory.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'configserver') 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); -- cgit v1.2.3