Skip to content
Snippets Groups Projects
Unverified Commit e67b2654 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

BUG: move directories

parent c02813fd
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.LinkOption;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
......@@ -290,6 +291,21 @@ public class FileUtils {
}
}
}
private static boolean exists(File file) {
return java.nio.file.Files.exists(file.toPath(), LinkOption.NOFOLLOW_LINKS);
}
private static void moveReplace(File file, File target) throws IOException {
if(exists(target)) {
org.apache.commons.io.FileUtils.forceDelete(target);
}
if (java.nio.file.Files.isDirectory(file.toPath(), LinkOption.NOFOLLOW_LINKS)) {
org.apache.commons.io.FileUtils.moveDirectory(file, target);
} else {
org.apache.commons.io.FileUtils.moveFile(file, target);
}
}
public static Undoable rename(final File file, final File target) throws Message, IOException {
final File backup;
......@@ -302,17 +318,17 @@ public class FileUtils {
public void cleanUp() {}
};
}
if (target.exists()) {
if (exists(target)) {
// in case this is a update transaction, the old version of the file
// must be stored somewhere until the transaction is done.
final File tmp = new File(new File(FileSystem.getTmp()), target.getName() + Utils.getUID());
java.nio.file.Files.move(target.toPath(), tmp.toPath());
moveReplace(target, tmp);
backup = tmp;
} else {
backup = null;
}
try {
java.nio.file.Files.move(file.toPath(), target.toPath());
moveReplace(file, target);
return new UndoHandler() {
private File _backup = backup;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment