Fix DirectoryNotEmptyException on downloads move

This commit is contained in:
crschnick 2024-07-29 21:47:24 +00:00
parent 65f51b8c2e
commit ebedd332bb

View file

@ -163,7 +163,12 @@ public class BrowserTransferModel {
var files = toMove.stream().map(item -> item.getLocalFile()).toList();
var downloads = DesktopHelper.getDownloadsDirectory();
for (Path file : files) {
Files.move(file, downloads.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
var target = downloads.resolve(file.getFileName());
// Prevent DirectoryNotEmptyException
if (Files.exists(target) && Files.isDirectory(target)) {
Files.delete(target);
}
Files.move(file, target, StandardCopyOption.REPLACE_EXISTING);
}
DesktopHelper.browseFileInDirectory(downloads.resolve(files.getFirst().getFileName()));
}