Upload manager changes
This commit is contained in:
@@ -95,6 +95,11 @@ CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriv
|
||||
_fileThread(siaCurl, siaDriveConfig, [this](const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) { this->FileThreadCallback(siaCurl, siaDriveConfig); })
|
||||
{
|
||||
CreateTableIfNotFound(&_uploadDatabase, UPLOAD_TABLE, UPLOAD_TABLE_COLUMNS);
|
||||
|
||||
// TODO Delete all .siadrive.temp
|
||||
// TODO Delete all .siadrive
|
||||
// TODO Search for removed
|
||||
// TODO Search for incomplete
|
||||
StartAutoThread();
|
||||
_fileThread.StartAutoThread();
|
||||
}
|
||||
@@ -132,7 +137,46 @@ void CUploadManager::FileAction(const String& siaPath, const String& filePath, c
|
||||
|
||||
if (remove)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_uploadMutex);
|
||||
SQLite::Statement query(_uploadDatabase, QUERY_STATUS);
|
||||
query.bind("@sia_path", CW2A(siaPath.c_str()).m_psz);
|
||||
if (query.executeStep())
|
||||
{
|
||||
String filePath = CA2W(query.getColumn(3)).m_psz;
|
||||
UploadStatus uploadStatus = static_cast<UploadStatus>(static_cast<unsigned>(query.getColumn(5)));
|
||||
if (uploadStatus == UploadStatus::Remove)
|
||||
{
|
||||
if (::PathFileExists(filePath.c_str()))
|
||||
{
|
||||
if (RetryDeleteFileIfExists(filePath.c_str()))
|
||||
{
|
||||
if (!RetryDeleteFileIfExists(siaDriveFilePath))
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath)));
|
||||
}
|
||||
|
||||
// TODO Delete from database
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemoved(siaPath, filePath)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Error condition
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO Delete from database
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLite::Exception e)
|
||||
{
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseExceptionOccurred(e)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -333,7 +377,7 @@ void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig
|
||||
SiaCurlError cerror = siaCurl.Post(String(L"/renter/upload/") + siaPath, { {L"source", filePath} }, response);
|
||||
if (ApiSuccess(cerror))
|
||||
{
|
||||
SET_STATUS(UploadStatus::Uploading, UploadComplete, ModifyUploadStatusFailed)
|
||||
SET_STATUS(UploadStatus::Uploading, UploadToSiaStarted, ModifyUploadStatusFailed)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,6 +539,7 @@ UploadError CUploadManager::Remove(const String& siaPath)
|
||||
if (query.executeStep())
|
||||
{
|
||||
String filePath = CA2W(query.getColumn(3)).m_psz;
|
||||
String siaDriveFilePath = CA2W(query.getColumn(4)).m_psz;
|
||||
UploadStatus uploadStatus = static_cast<UploadStatus>(static_cast<unsigned>(query.getColumn(5)));
|
||||
switch (uploadStatus)
|
||||
{
|
||||
@@ -505,6 +550,10 @@ UploadError CUploadManager::Remove(const String& siaPath)
|
||||
{
|
||||
SET_STATUS(UploadStatus::Remove, UploadStatusSetToRemoved, ModifyUploadStatusFailed)
|
||||
remove = statusUpdated;
|
||||
if (!statusUpdated)
|
||||
{
|
||||
ret = UploadError::DatabaseError;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -514,12 +563,14 @@ UploadError CUploadManager::Remove(const String& siaPath)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (remove)
|
||||
{
|
||||
std::lock_guard<std::mutex> l2(_fileQueueMutex);
|
||||
_fileQueue.push_back([=]() { this->FileAction(siaPath, nullptr, nullptr, nullptr, true); });
|
||||
if (remove)
|
||||
{
|
||||
std::lock_guard<std::mutex> l2(_fileQueueMutex);
|
||||
_fileQueue.push_back([=]() { this->FileAction(siaPath, filePath, nullptr, siaDriveFilePath, true); });
|
||||
|
||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemoveAdded(siaPath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLite::Exception e)
|
||||
|
@@ -175,6 +175,38 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class UploadToSiaStarted :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
UploadToSiaStarted(const String& siaPath, const String& filePath) :
|
||||
_siaPath(siaPath),
|
||||
_filePath(filePath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~UploadToSiaStarted()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const String _siaPath;
|
||||
const String _filePath;
|
||||
|
||||
public:
|
||||
virtual String GetSingleLineMessage() const override
|
||||
{
|
||||
return L"UploadToSiaStarted|SP|" + _siaPath + L"|FP|" + _filePath;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new UploadToSiaStarted(_siaPath, _filePath));
|
||||
}
|
||||
};
|
||||
|
||||
class UploadComplete :
|
||||
public CEvent
|
||||
{
|
||||
@@ -207,6 +239,38 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FileRemoved :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
FileRemoved(const String& siaPath, const String& filePath) :
|
||||
_siaPath(siaPath),
|
||||
_filePath(filePath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~FileRemoved()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const String _siaPath;
|
||||
const String _filePath;
|
||||
|
||||
public:
|
||||
virtual String GetSingleLineMessage() const override
|
||||
{
|
||||
return L"FileRemoved|SP|" + _siaPath + L"|FP|" + _filePath;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new FileRemoved(_siaPath, _filePath));
|
||||
}
|
||||
};
|
||||
|
||||
class UploadStatusSetToModified :
|
||||
public CEvent
|
||||
{
|
||||
@@ -617,6 +681,36 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FileRemoveAdded :
|
||||
public CEvent
|
||||
{
|
||||
public:
|
||||
FileRemoveAdded(const String& siaPath) :
|
||||
_siaPath(siaPath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~FileRemoveAdded()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const String _siaPath;
|
||||
|
||||
public:
|
||||
virtual String GetSingleLineMessage() const override
|
||||
{
|
||||
return L"FileRemoveAdded|SP|" + _siaPath;
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<CEvent> Clone() const override
|
||||
{
|
||||
return std::shared_ptr<CEvent>(new FileRemoveAdded(_siaPath));
|
||||
}
|
||||
};
|
||||
|
||||
class SourceFileNotFound :
|
||||
public CEvent
|
||||
{
|
||||
|
Reference in New Issue
Block a user