Skip to content

Commit

Permalink
fix: tmp file moving across filesystems (#148)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
igorbernstein2 committed Dec 16, 2021
1 parent 985e068 commit 89fbce3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,11 @@
<artifactId>commons-compress</artifactId>
<version>1.21</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
9 changes: 4 additions & 5 deletions src/main/java/com/google/cloud/DownloadComponentsMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 89fbce3

Please sign in to comment.