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); static SString UploadStatusToString(const _UploadStatus& uploadStatus);
public: 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); _UploadStatus GetUploadStatus(const SString& siaPath);
CSiaError<_UploadErrorCode> Remove(const SString& siaPath); CSiaError<_UploadErrorCode> Remove(const SString& siaPath);
}; };

View File

@@ -4,19 +4,20 @@
#include <eventsystem.h> #include <eventsystem.h>
#include <siadriveconfig.h> #include <siadriveconfig.h>
#include <filepath.h> #include <filepath.h>
#include "../../include/siadrive_dokan_api/siadokandrive.h"
using namespace Sia::Api; using namespace Sia::Api;
#define TABLE_CREATE L"create table if not exists %s (%s);" #define TABLE_CREATE L"create table if not exists %s (%s);"
#define UPLOAD_TABLE L"upload_table" #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_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_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_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 "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 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 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 DELETE_UPLOAD "delete from upload_table where sia_path=@sia_path;"
#define SET_STATUS(status, success_event, fail_event)\ #define SET_STATUS(status, success_event, fail_event)\
@@ -111,12 +112,9 @@ void CUploadManager::DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriv
auto fileList = fileTree->GetFileList(); auto fileList = fileTree->GetFileList();
// TODO Implement this // 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; 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; UploadError ret;
@@ -268,33 +266,27 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
try try
{ {
bool addToDatabase = true;
// Check upload status
SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH); SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH);
query.bind("@sia_path", SString::ToUtf8(siaPath).c_str()); query.bind("@sia_path", SString::ToUtf8(siaPath).c_str());
// Check uploading
bool addToDatabase = true;
if (query.executeStep()) 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")))); UploadStatus uploadStatus = static_cast<UploadStatus>(static_cast<unsigned>(query.getColumn(query.getColumnIndex("status"))));
if (uploadStatus == UploadStatus::Uploading) addToDatabase = (uploadStatus == UploadStatus::Uploading) && (lastModified != modifiedTime) && HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
{
// TODO only remove if file changed
addToDatabase = HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
}
else if (uploadStatus == UploadStatus::Queued)
{
addToDatabase = false;
}
} }
if (addToDatabase) if (addToDatabase)
{ {
// Add to db
try try
{ {
// Add to db
SQLite::Statement insert(_uploadDatabase, INSERT_UPLOAD); SQLite::Statement insert(_uploadDatabase, INSERT_UPLOAD);
insert.bind("@sia_path", SString::ToUtf8(siaPath).c_str()); insert.bind("@sia_path", SString::ToUtf8(siaPath).c_str());
insert.bind("@file_path", SString::ToUtf8(filePath).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)); insert.bind("@status", static_cast<unsigned>(UploadStatus::Queued));
if (insert.exec() == 1) if (insert.exec() == 1)
{ {

View File

@@ -138,10 +138,16 @@ private:
if (size > 0) if (size > 0)
{ {
// TODO Handle error return // 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 else
{ {
// TODO Handle error return
// Treat 0 length files as deleted in Sia - cache retains 0-length // Treat 0 length files as deleted in Sia - cache retains 0-length
_uploadManager->Remove(openFileInfo.SiaPath); _uploadManager->Remove(openFileInfo.SiaPath);
} }