From 543854ca276b275b6c26a5b2d744a0588d355fe7 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 22 Feb 2017 19:50:16 -0600 Subject: [PATCH] Upload manager changes --- SiaDrive.Api/UploadManager.cpp | 38 +++++++++++++++++++++++++++------- SiaDrive.Api/UploadManager.h | 1 + 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/SiaDrive.Api/UploadManager.cpp b/SiaDrive.Api/UploadManager.cpp index 0e7ba55..1295c10 100644 --- a/SiaDrive.Api/UploadManager.cpp +++ b/SiaDrive.Api/UploadManager.cpp @@ -162,6 +162,7 @@ void CUploadManager::AddOrUpdate(const String& siaPath, const String& filePath) query.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); query.bind("@status1", static_cast(UploadStatus::Uploading)); query.bind("@status2", static_cast(UploadStatus::Modified)); + // Check copying if (query.executeStep()) { if (static_cast(static_cast(query.getColumn(2))) == UploadStatus::Uploading) @@ -172,16 +173,39 @@ void CUploadManager::AddOrUpdate(const String& siaPath, const String& filePath) } else { - - String tempPath; - tempPath.resize(MAX_PATH + 1); - PathCombine(&tempPath[0], CA2W(_siaDriveConfig->GetTempFolder().c_str()), GenerateSha256(filePath).c_str()); - SQLite::Statement addOrUpdate(_uploadDatabase, ADD_UPDATE_UPLOAD); + /*SQLite::Statement addOrUpdate(_uploadDatabase, ADD_UPDATE_UPLOAD); addOrUpdate.bind("@sia_path", CW2A(siaPath.c_str()).m_psz); addOrUpdate.bind("@file_path", CW2A(filePath.c_str()).m_psz); addOrUpdate.bind("@temp_path", CW2A(tempPath.c_str()).m_psz); - addOrUpdate.bind("@status", static_cast(UploadStatus::Queued)); - tempPath = L""; + addOrUpdate.bind("@status", static_cast(UploadStatus::Queued));*/ + + // While copy is active, point to normal file. + // After copy, use temp file as real file until upload is complete + // This allows modifications to the file to occur in a more timely manner. + // Error Scenarios: + // Crash before db update to status copying - file will be re-uploaded automatically, if complete; otherwise, deleted + // Need to keep track of files as being copied and then there status + // Crash Scenarios: + // Crash before copy begins - on startup, check for copying status with no .siadrive + // Crash during copy - on startup, check for copying status and delete .siadrive + // Crash after copy but before db update - on startup, check for copying status and delete .siadrive + String tempPath; + tempPath.resize(MAX_PATH + 1); + PathCombine(&tempPath[0], CA2W(_siaDriveConfig->GetTempFolder().c_str()), (GenerateSha256(filePath) + L".siadrive").c_str()); + + // Queue this + if (::CopyFile(filePath.c_str(), tempPath.c_str(), FALSE)) + { + tempPath = L""; + } + else + { + if (!::DeleteFile(tempPath.c_str())) + { + + } + // error condition + } } } diff --git a/SiaDrive.Api/UploadManager.h b/SiaDrive.Api/UploadManager.h index 4438de0..bda7f75 100644 --- a/SiaDrive.Api/UploadManager.h +++ b/SiaDrive.Api/UploadManager.h @@ -13,6 +13,7 @@ public: enum class _UploadStatus : unsigned { NotFound, + Copying, Queued, Modified, Uploading,