1
0

Upload manager fixes

This commit is contained in:
Scott E. Graves
2017-04-04 22:37:15 -05:00
parent 03f93c087c
commit 26bc887dda
3 changed files with 21 additions and 23 deletions

View File

@@ -65,7 +65,7 @@ public:
static SString UploadStatusToString(const _UploadStatus& uploadStatus);
public:
CSiaError<_UploadErrorCode> AddOrUpdate(const SString& siaPath, SString filePath);
CSiaError<_UploadErrorCode> AddOrUpdate(const SString& siaPath, SString filePath, const std::uint64_t& lastModified);
_UploadStatus GetUploadStatus(const SString& siaPath);
CSiaError<_UploadErrorCode> Remove(const SString& siaPath);
};

View File

@@ -4,19 +4,20 @@
#include <eventsystem.h>
#include <siadriveconfig.h>
#include <filepath.h>
#include "../../include/siadrive_dokan_api/siadokandrive.h"
using namespace Sia::Api;
#define TABLE_CREATE L"create table if not exists %s (%s);"
#define UPLOAD_TABLE L"upload_table"
#define UPLOAD_TABLE_COLUMNS L"id integer primary key autoincrement, sia_path text unique not null, file_path text unique not null, status integer not null"
#define UPLOAD_TABLE_COLUMNS L"id integer primary key autoincrement, sia_path text unique not null, file_path text unique not null, status integer not null, modified_time integer not null"
#define QUERY_STATUS "select * from upload_table where sia_path=@sia_path order by id desc limit 1;"
#define QUERY_UPLOADS_BY_STATUS "select * from upload_table where status=@status order by id desc limit 1;"
#define QUERY_UPLOAD_COUNT_BY_STATUS "select count(id) from upload_table where status=@status;"
#define QUERY_UPLOADS_BY_SIA_PATH "select * from upload_table where sia_path=@sia_path order by id desc limit 1;"
#define QUERY_UPLOADS_BY_SIA_PATH_AND_STATUS "select * from upload_table where sia_path=@sia_path and status=@status order by id desc limit 1;"
#define UPDATE_STATUS "update upload_table set status=@status where sia_path=@sia_path;"
#define INSERT_UPLOAD "insert into upload_table (sia_path, status, file_path) values (@sia_path, @status, @file_path);"
#define INSERT_UPLOAD "insert into upload_table (sia_path, status, file_path, modified_time) values (@sia_path, @status, @file_path, @modified_time);"
#define DELETE_UPLOAD "delete from upload_table where sia_path=@sia_path;"
#define SET_STATUS(status, success_event, fail_event)\
@@ -111,12 +112,9 @@ void CUploadManager::DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriv
auto fileList = fileTree->GetFileList();
// TODO Implement this
}
else
else if (isStartup)
{
if (isStartup)
{
throw StartupException(L"Failed to get Sia files");
}
throw StartupException(L"Failed to get Sia files");
}
}
@@ -252,7 +250,7 @@ UploadStatus CUploadManager::GetUploadStatus(const SString& siaPath)
return uploadStatus;
}
UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath)
UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath, const std::uint64_t& lastModified)
{
UploadError ret;
@@ -268,33 +266,27 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
try
{
bool addToDatabase = true;
// Check upload status
SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH);
query.bind("@sia_path", SString::ToUtf8(siaPath).c_str());
// Check uploading
bool addToDatabase = true;
if (query.executeStep())
{
std::uint64_t modifiedTime = query.getColumn(query.getColumnIndex("modified_time")).getInt64();
UploadStatus uploadStatus = static_cast<UploadStatus>(static_cast<unsigned>(query.getColumn(query.getColumnIndex("status"))));
if (uploadStatus == UploadStatus::Uploading)
{
// TODO only remove if file changed
addToDatabase = HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
}
else if (uploadStatus == UploadStatus::Queued)
{
addToDatabase = false;
}
addToDatabase = (uploadStatus == UploadStatus::Uploading) && (lastModified != modifiedTime) && HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
}
if (addToDatabase)
{
// Add to db
try
{
// Add to db
SQLite::Statement insert(_uploadDatabase, INSERT_UPLOAD);
insert.bind("@sia_path", SString::ToUtf8(siaPath).c_str());
insert.bind("@file_path", SString::ToUtf8(filePath).c_str());
insert.bind("@modified_time", static_cast<long long>(lastModified));
insert.bind("@status", static_cast<unsigned>(UploadStatus::Queued));
if (insert.exec() == 1)
{

View File

@@ -138,10 +138,16 @@ private:
if (size > 0)
{
// TODO Handle error return
_uploadManager->AddOrUpdate(openFileInfo.SiaPath, openFileInfo.CacheFilePath);
// Retrieve the file times for the file.
FILETIME fileTimes[3];
if (GetFileTime(openFileInfo.FileHandle, &fileTimes[0], &fileTimes[1], &fileTimes[2]))
{
_uploadManager->AddOrUpdate(openFileInfo.SiaPath, openFileInfo.CacheFilePath, *reinterpret_cast<std::uint16_t*>(&fileTimes[2]));
}
}
else
{
// TODO Handle error return
// Treat 0 length files as deleted in Sia - cache retains 0-length
_uploadManager->Remove(openFileInfo.SiaPath);
}