diff --git a/src/onedrive.d b/src/onedrive.d index 0fc82ab0..8204d843 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -1158,8 +1158,13 @@ final class OneDriveApi { // Threshold for displaying download bar long thresholdFileSize = 4 * 2^^20; // 4 MiB - // open file as write in binary mode - auto file = File(filename, "wb"); + + // To support marking of partially-downloaded files, + string originalFilename = filename; + string downloadFilename = filename ~ ".partial"; + + // open downloadFilename as write in binary mode + auto file = File(downloadFilename, "wb"); // function scopes scope(exit) { @@ -1253,6 +1258,9 @@ final class OneDriveApi } } + // Rename downloaded file + rename(downloadFilename, originalFilename); + // Check the HTTP response code, which, if a 429, will also check response headers checkHttpCode(); }