Merge pull request #267 from mslxl/javafx
Fix `Unable to move temp file`, `File::renameTo` is problematic.
This commit is contained in:
@@ -202,8 +202,11 @@ public class FileDownloadTask extends Task {
|
|||||||
throw new IOException("Unable to delete existent file " + file);
|
throw new IOException("Unable to delete existent file " + file);
|
||||||
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
|
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
|
||||||
throw new IOException("Unable to make parent directory " + file);
|
throw new IOException("Unable to make parent directory " + file);
|
||||||
if (!temp.renameTo(file))
|
try {
|
||||||
throw new IOException("Unable to move temp file from " + temp + " to " + file);
|
FileUtils.cutFile(temp, file);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException("Unable to move temp file from " + temp + " to " + file, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloaded != contentLength)
|
if (downloaded != contentLength)
|
||||||
|
|||||||
@@ -236,7 +236,12 @@ public final class FileUtils {
|
|||||||
doCopyFile(srcFile, destFile);
|
doCopyFile(srcFile, destFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doCopyFile(File srcFile, File destFile)
|
public static void cutFile(File srcFile, File destFile) throws IOException {
|
||||||
|
copyFile(srcFile, destFile);
|
||||||
|
srcFile.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void doCopyFile(File srcFile, File destFile)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user