From 7c112304b558fe1258b2a07afdddb9a411325e78 Mon Sep 17 00:00:00 2001 From: lanhin Date: Wed, 23 Nov 2016 23:10:37 +0800 Subject: [PATCH] Bug fixed: 1. Replace mkdirRecurse with mkdir to deal nested directory;2. Before download an item, check if its dirName exists, if not, build it. --- src/onedrive.d | 6 +++++- src/sync.d | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/onedrive.d b/src/onedrive.d index 6e57294c..53009215 100644 --- a/src/onedrive.d +++ b/src/onedrive.d @@ -100,10 +100,14 @@ final class OneDriveApi void downloadById(const(char)[] id, string saveToPath) { checkAccessTokenExpired(); + import std.file; scope(failure) { - import std.file; if (exists(saveToPath)) remove(saveToPath); } + // mkdir if need, or File(saveToPath, "wb") may fail + if ( !exists(dirName(saveToPath)) ) { + mkdirRecurse(dirName(saveToPath)); + } const(char)[] url = itemByIdUrl ~ id ~ "/content?AVOverride=1"; download(url, saveToPath); } diff --git a/src/sync.d b/src/sync.d index 1789e777..634b2dd7 100644 --- a/src/sync.d +++ b/src/sync.d @@ -243,7 +243,8 @@ final class SyncEngine break; case ItemType.dir: log.log("Creating directory: ", path); - mkdir(path); + //Use mkdirRecuse to deal nested dir + mkdirRecurse(path); break; } setTimes(path, item.mtime, item.mtime);