Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tmp file moving across filesystems #148

Merged
merged 1 commit into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
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
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