Fix Unable move temp file on Arch Linux

This commit is contained in:
mslxl
2018-02-05 16:24:44 +08:00
parent 3abb96e5b9
commit 826a6bf868
2 changed files with 11 additions and 3 deletions

View File

@@ -202,8 +202,11 @@ public class FileDownloadTask extends Task {
throw new IOException("Unable to delete existent file " + file);
if (!FileUtils.makeDirectory(file.getAbsoluteFile().getParentFile()))
throw new IOException("Unable to make parent directory " + file);
if (!temp.renameTo(file))
throw new IOException("Unable to move temp file from " + temp + " to " + file);
try {
FileUtils.cutFile(temp, file);
} catch (Exception e) {
throw new IOException("Unable to move temp file from " + temp + " to " + file, e);
}
}
if (downloaded != contentLength)

View File

@@ -236,7 +236,12 @@ public final class FileUtils {
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 {
Files.copy(srcFile.toPath(), destFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
}