1
0

Upload manager changes

This commit is contained in:
Scott E. Graves
2017-02-22 19:50:16 -06:00
parent b7cfb942a2
commit 543854ca27
2 changed files with 32 additions and 7 deletions

View File

@@ -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<unsigned>(UploadStatus::Uploading));
query.bind("@status2", static_cast<unsigned>(UploadStatus::Modified));
// Check copying
if (query.executeStep())
{
if (static_cast<UploadStatus>(static_cast<unsigned>(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<unsigned>(UploadStatus::Queued));
tempPath = L"";
addOrUpdate.bind("@status", static_cast<unsigned>(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
}
}
}

View File

@@ -13,6 +13,7 @@ public:
enum class _UploadStatus : unsigned
{
NotFound,
Copying,
Queued,
Modified,
Uploading,