From 89fbce3218cfb9304d416f9ba6e45db147ac56c0 Mon Sep 17 00:00:00 2001 From: Igor Bernstein Date: Thu, 16 Dec 2021 14:17:58 -0500 Subject: [PATCH] fix: tmp file moving across filesystems (#148) File.move doesn't work across non-empty directories, so it fails when downloadComponent tries to move the artifacts to their file destination. Instead use comons-io helper to fallback to copies --- pom.xml | 6 ++++++ .../java/com/google/cloud/DownloadComponentsMojo.java | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 3e533e1..c5f0c1b 100644 --- a/pom.xml +++ b/pom.xml @@ -95,5 +95,11 @@ commons-compress 1.21 + + + commons-io + commons-io + 2.6 + diff --git a/src/main/java/com/google/cloud/DownloadComponentsMojo.java b/src/main/java/com/google/cloud/DownloadComponentsMojo.java index b9befe2..fc46d81 100644 --- a/src/main/java/com/google/cloud/DownloadComponentsMojo.java +++ b/src/main/java/com/google/cloud/DownloadComponentsMojo.java @@ -35,6 +35,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -53,6 +54,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.Lists; +import org.apache.commons.io.FileUtils; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -238,10 +240,7 @@ private void updateCachedManifest() throws IOException { } } - @SuppressWarnings("unused") - boolean ignored = localCache.delete(); - - Files.move(tempFile.toPath(), localCache.toPath()); + Files.move(tempFile.toPath(), localCache.toPath(), StandardCopyOption.REPLACE_EXISTING); } /** Parse the locally cached manifest and extract the relevant components. */ @@ -369,7 +368,7 @@ private void downloadComponent(Component component) throws IOException, NoSuchAl // Move it into place File localPath = getComponentPath(component); deleteRecursively(localPath); - Files.move(tmpPath.toPath(), localPath.toPath()); + FileUtils.moveDirectory(tmpPath, localPath); } private static void deleteRecursively(File directory) {