Fix downloads move being unreliable

This commit is contained in:
crschnick 2024-09-11 22:31:28 +00:00
parent c5f99af866
commit c38962ef2e

View file

@ -10,21 +10,18 @@ import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.DesktopHelper; import io.xpipe.app.util.DesktopHelper;
import io.xpipe.app.util.ShellTemp; import io.xpipe.app.util.ShellTemp;
import io.xpipe.app.util.ThreadHelper; import io.xpipe.app.util.ThreadHelper;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableBooleanValue; import javafx.beans.value.ObservableBooleanValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import lombok.Value; import lombok.Value;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -162,13 +159,14 @@ public class BrowserTransferModel {
var files = toMove.stream().map(item -> item.getLocalFile()).toList(); var files = toMove.stream().map(item -> item.getLocalFile()).toList();
var downloads = DesktopHelper.getDownloadsDirectory(); var downloads = DesktopHelper.getDownloadsDirectory();
Files.createDirectories(downloads);
for (Path file : files) { for (Path file : files) {
var target = downloads.resolve(file.getFileName()); var target = downloads.resolve(file.getFileName());
// Prevent DirectoryNotEmptyException // Prevent DirectoryNotEmptyException
if (Files.exists(target) && Files.isDirectory(target)) { if (Files.exists(target) && Files.isDirectory(target)) {
FileUtils.deleteDirectory(target.toFile()); FileUtils.deleteDirectory(target.toFile());
} }
Files.move(file, target, StandardCopyOption.REPLACE_EXISTING); FileUtils.moveDirectory(file.toFile(),target.toFile());
} }
DesktopHelper.browseFileInDirectory(downloads.resolve(files.getFirst().getFileName())); DesktopHelper.browseFileInDirectory(downloads.resolve(files.getFirst().getFileName()));
} }