Upload manager changes
This commit is contained in:
@@ -97,6 +97,7 @@ CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriv
|
|||||||
{
|
{
|
||||||
CreateTableIfNotFound(&_uploadDatabase, UPLOAD_TABLE, UPLOAD_TABLE_COLUMNS);
|
CreateTableIfNotFound(&_uploadDatabase, UPLOAD_TABLE, UPLOAD_TABLE_COLUMNS);
|
||||||
|
|
||||||
|
// Clean-up cache folder
|
||||||
if (!RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive"))
|
if (!RecurDeleteFilesByExtentsion(CA2W(siaDriveConfig->GetCacheFolder().c_str()).m_psz, L".siadrive"))
|
||||||
{
|
{
|
||||||
throw StartupException(L"Failed to remove '.siadrive' files");
|
throw StartupException(L"Failed to remove '.siadrive' files");
|
||||||
@@ -107,20 +108,25 @@ CUploadManager::CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriv
|
|||||||
throw StartupException(L"Failed to remove '.siadrive.temp' files");
|
throw StartupException(L"Failed to remove '.siadrive.temp' files");
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateQueueOnStartup();
|
// Re-add files to file action queue
|
||||||
|
UpdateFileQueueOnStartup();
|
||||||
|
|
||||||
|
// Detect files that have been removed since last startup
|
||||||
DeleteFilesRemovedFromSia(siaCurl, siaDriveConfig, true);
|
DeleteFilesRemovedFromSia(siaCurl, siaDriveConfig, true);
|
||||||
|
|
||||||
|
// Begin normal processing
|
||||||
StartAutoThread();
|
StartAutoThread();
|
||||||
_fileThread.StartAutoThread();
|
_fileThread.StartAutoThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
CUploadManager::~CUploadManager()
|
CUploadManager::~CUploadManager()
|
||||||
{
|
{
|
||||||
|
// Stop all processing
|
||||||
_fileThread.StopAutoThread();
|
_fileThread.StopAutoThread();
|
||||||
StopAutoThread();
|
StopAutoThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUploadManager::UpdateQueueOnStartup()
|
void CUploadManager::UpdateFileQueueOnStartup()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -423,11 +429,20 @@ void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig
|
|||||||
{
|
{
|
||||||
return ptr->GetSiaPath() == siaPath;
|
return ptr->GetSiaPath() == siaPath;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Removed by another client
|
||||||
if (it == fileList.end())
|
if (it == fileList.end())
|
||||||
{
|
{
|
||||||
// error condition - should always exist. delete from db and log warning, but continue processing
|
SET_STATUS(UploadStatus::Remove, ExternallyRemovedFileDetected, ModifyUploadStatusFailed)
|
||||||
|
if (statusUpdated)
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> l2(_fileQueueMutex);
|
||||||
|
_fileQueue.push_back([=]() { this->FileAction(CSiaCurl(GetHostConfig()), siaPath, filePath, nullptr, siaDriveFilePath, true); });
|
||||||
|
|
||||||
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FileRemoveAdded(siaPath)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Changed file detected
|
||||||
else if (uploadStatus == UploadStatus::Modified)
|
else if (uploadStatus == UploadStatus::Modified)
|
||||||
{
|
{
|
||||||
json response;
|
json response;
|
||||||
@@ -442,6 +457,7 @@ void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig
|
|||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FailedToDeleteFromSia(siaPath, filePath, cerror)));
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(FailedToDeleteFromSia(siaPath, filePath, cerror)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Upload is complete
|
||||||
else if ((*it)->GetUploadProgress() >= 100)
|
else if ((*it)->GetUploadProgress() >= 100)
|
||||||
{
|
{
|
||||||
SET_STATUS(UploadStatus::Complete, UploadComplete, ModifyUploadStatusFailed)
|
SET_STATUS(UploadStatus::Complete, UploadComplete, ModifyUploadStatusFailed)
|
||||||
@@ -450,9 +466,9 @@ void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig
|
|||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath)));
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DeleteSiaDriveFileFailed(siaPath, filePath, siaDriveFilePath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Upload still active, don't process another file
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// upload still active
|
|
||||||
processNext = false;
|
processNext = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,18 +610,18 @@ UploadError CUploadManager::AddOrUpdate(const String& siaPath, String filePath)
|
|||||||
insert.bind("@file_path", CW2A(filePath.c_str()).m_psz);
|
insert.bind("@file_path", CW2A(filePath.c_str()).m_psz);
|
||||||
insert.bind("@sd_file_path", CW2A(siaDriveFileName.c_str()).m_psz);
|
insert.bind("@sd_file_path", CW2A(siaDriveFileName.c_str()).m_psz);
|
||||||
insert.bind("@status", static_cast<unsigned>(UploadStatus::Copying));
|
insert.bind("@status", static_cast<unsigned>(UploadStatus::Copying));
|
||||||
if (insert.exec() != 1)
|
if (insert.exec() == 1)
|
||||||
{
|
|
||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseInsertFailed(siaPath, filePath, CA2W(insert.getErrorMsg()).m_psz)));
|
|
||||||
ret = UploadError::DatabaseError;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Queue file upload operation
|
// Queue file upload operation
|
||||||
std::lock_guard<std::mutex> l2(_fileQueueMutex);
|
std::lock_guard<std::mutex> l2(_fileQueueMutex);
|
||||||
_fileQueue.push_back([=]() { this->FileAction(CSiaCurl(GetHostConfig()), siaPath, filePath, tempSourcePath, siaDriveFilePath, false); });
|
_fileQueue.push_back([=]() { this->FileAction(CSiaCurl(GetHostConfig()), siaPath, filePath, tempSourcePath, siaDriveFilePath, false); });
|
||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(NewFileAdded(siaPath, filePath, siaDriveFilePath)));
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(NewFileAdded(siaPath, filePath, siaDriveFilePath)));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseInsertFailed(siaPath, filePath, CA2W(insert.getErrorMsg()).m_psz)));
|
||||||
|
ret = UploadError::DatabaseError;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SQLite::Exception e)
|
catch (SQLite::Exception e)
|
||||||
{
|
{
|
||||||
@@ -681,7 +697,6 @@ UploadError CUploadManager::Remove(const String& siaPath)
|
|||||||
{
|
{
|
||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseExceptionOccurred(e)));
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseExceptionOccurred(e)));
|
||||||
ret = UploadError::DatabaseError;
|
ret = UploadError::DatabaseError;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -60,7 +60,7 @@ private:
|
|||||||
void FileThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
void FileThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||||
void HandleFileRemove(const CSiaCurl& siaCurl, const String& siaPath, const String& siaDriveFilePath);
|
void HandleFileRemove(const CSiaCurl& siaCurl, const String& siaPath, const String& siaDriveFilePath);
|
||||||
void HandleAddFile(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath);
|
void HandleAddFile(const String& siaPath, const String& filePath, const String& tempSourcePath, const String& siaDriveFilePath);
|
||||||
void UpdateQueueOnStartup();
|
void UpdateFileQueueOnStartup();
|
||||||
void DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, const bool& isStartup = false);
|
void DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, const bool& isStartup = false);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -145,6 +145,38 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ExternallyRemovedFileDetected :
|
||||||
|
public CEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExternallyRemovedFileDetected(const String& siaPath, const String& filePath) :
|
||||||
|
_siaPath(siaPath),
|
||||||
|
_filePath(filePath)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ExternallyRemovedFileDetected()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const String _siaPath;
|
||||||
|
const String _filePath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual String GetSingleLineMessage() const override
|
||||||
|
{
|
||||||
|
return L"ExternallyRemovedFileDetected|SP|" + _siaPath + L"|FP|" + _filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual std::shared_ptr<CEvent> Clone() const override
|
||||||
|
{
|
||||||
|
return std::shared_ptr<CEvent>(new ExternallyRemovedFileDetected(_siaPath, _filePath));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ModifiedUploadQueued :
|
class ModifiedUploadQueued :
|
||||||
public CEvent
|
public CEvent
|
||||||
{
|
{
|
||||||
|
@@ -397,6 +397,7 @@ public:
|
|||||||
{
|
{
|
||||||
_siaApi = siaApi;
|
_siaApi = siaApi;
|
||||||
_siaDriveConfig = siaDriveConfig;
|
_siaDriveConfig = siaDriveConfig;
|
||||||
|
// May spend a little wait time here while files are cleaned-up and re-added to queue
|
||||||
_uploadManager.reset(new CUploadManager(CSiaCurl(siaApi->GetHostConfig()), siaDriveConfig));
|
_uploadManager.reset(new CUploadManager(CSiaCurl(siaApi->GetHostConfig()), siaDriveConfig));
|
||||||
_dokanOps.Cleanup = nullptr;
|
_dokanOps.Cleanup = nullptr;
|
||||||
_dokanOps.CloseFile = Sia_CloseFile;
|
_dokanOps.CloseFile = Sia_CloseFile;
|
||||||
|
Reference in New Issue
Block a user