Partial fix for duplicate uploads
This commit is contained in:
@@ -21,8 +21,7 @@ public:
|
|||||||
NotFound,
|
NotFound,
|
||||||
Queued,
|
Queued,
|
||||||
Uploading,
|
Uploading,
|
||||||
Complete,
|
Complete
|
||||||
Error
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class _UploadErrorCode
|
enum class _UploadErrorCode
|
||||||
|
@@ -81,10 +81,18 @@ std::vector<SString> CSiaApi::_CSiaFileTree::QueryDirectories(SString rootFolder
|
|||||||
SString path = ("\\" + FilePath(v->GetSiaPath()).RemoveFileName()).Replace("/", "\\");
|
SString path = ("\\" + FilePath(v->GetSiaPath()).RemoveFileName()).Replace("/", "\\");
|
||||||
if (path.BeginsWith(rootFolder))
|
if (path.BeginsWith(rootFolder))
|
||||||
{
|
{
|
||||||
path = path.SubString(1, rootFolder.Length());
|
path = (rootFolder == "\\") ? path.SubString(1) : path.SubString(1, rootFolder.Length());
|
||||||
if (path.Length())
|
if (path.Length())
|
||||||
{
|
{
|
||||||
|
auto splitPaths = path.Split('\\');
|
||||||
|
if (splitPaths.size())
|
||||||
|
{
|
||||||
|
path = splitPaths[0];
|
||||||
|
if (std::find(ret.begin(), ret.end(), path) == ret.end())
|
||||||
|
{
|
||||||
|
ret.push_back(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -66,9 +66,6 @@ SString CUploadManager::UploadStatusToString(const UploadStatus& uploadStatus)
|
|||||||
case UploadStatus::Complete:
|
case UploadStatus::Complete:
|
||||||
return L"Complete";
|
return L"Complete";
|
||||||
|
|
||||||
case UploadStatus::Error:
|
|
||||||
return L"Error";
|
|
||||||
|
|
||||||
case UploadStatus::NotFound:
|
case UploadStatus::NotFound:
|
||||||
return L"Not Found";
|
return L"Not Found";
|
||||||
|
|
||||||
@@ -271,9 +268,8 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SQLite::Statement query(_uploadDatabase, QUERY_UPLOADS_BY_SIA_PATH_AND_STATUS);
|
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());
|
||||||
query.bind("@status", static_cast<unsigned>(UploadStatus::Uploading));
|
|
||||||
|
|
||||||
// Check uploading
|
// Check uploading
|
||||||
bool addToDatabase = true;
|
bool addToDatabase = true;
|
||||||
@@ -282,6 +278,7 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
|
|||||||
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)
|
if (uploadStatus == UploadStatus::Uploading)
|
||||||
{
|
{
|
||||||
|
// TODO only remove if file changed
|
||||||
addToDatabase = HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
addToDatabase = HandleFileRemove(CSiaCurl(GetHostConfig()), siaPath);
|
||||||
}
|
}
|
||||||
else if (uploadStatus == UploadStatus::Queued)
|
else if (uploadStatus == UploadStatus::Queued)
|
||||||
@@ -311,7 +308,7 @@ UploadError CUploadManager::AddOrUpdate(const SString& siaPath, SString filePath
|
|||||||
}
|
}
|
||||||
catch (SQLite::Exception e)
|
catch (SQLite::Exception e)
|
||||||
{
|
{
|
||||||
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseExceptionOccurred("AddOrUpdate(insert)", e)));
|
CEventSystem::EventSystem.NotifyEvent(CreateSystemEvent(DatabaseInsertFailed(siaPath, filePath, e.getErrorStr())));
|
||||||
ret = { UploadErrorCode::DatabaseError, e.getErrorStr() };
|
ret = { UploadErrorCode::DatabaseError, e.getErrorStr() };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user