Skip to content

Commit

Permalink
Fix file move: replace destination if exists
Browse files Browse the repository at this point in the history
The implementation was changed in aee7266 from com.google.common.io.Files which implicitly overwrites to java.nio.file.Files which does not.
  • Loading branch information
Luca Bassi authored and enricovianello committed Nov 19, 2024
1 parent 5e5cef1 commit be653fa
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -70,15 +71,15 @@ public void mv(File source, File dest) {

LOG.debug("mv: source={}, dest={}", source.getAbsolutePath(),
dest.getAbsolutePath());

try {

if (source.getCanonicalPath().equals(dest.getCanonicalPath())) {
throw new SameFileError("Source and destination files are the same");
}
// Overwrites the destination, if it exists
Files.move(source.toPath(), dest.toPath());

// Overwrites the destination, if it exists
Files.move(source.toPath(), dest.toPath(), StandardCopyOption.REPLACE_EXISTING);

} catch (IOException e) {
throw new StoRMWebDAVError(e.getMessage(), e);
Expand All @@ -100,7 +101,7 @@ public void cp(File source, File dest) {
dest.getAbsolutePath());

try {

if (source.getCanonicalPath().equals(dest.getCanonicalPath())) {
throw new SameFileError("Source and destination files are the same");
}
Expand Down

0 comments on commit be653fa

Please sign in to comment.