diff --git a/src/siadrive_api/uploadmanager.cpp b/src/siadrive_api/uploadmanager.cpp index 2835f43..ac8f7d8 100644 --- a/src/siadrive_api/uploadmanager.cpp +++ b/src/siadrive_api/uploadmanager.cpp @@ -310,15 +310,21 @@ void CUploadManager::AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig SString siaPath = static_cast(query.getColumn(query.getColumnIndex("sia_path"))); SString filePath = static_cast(query.getColumn(query.getColumnIndex("file_path"))); SString sdFilePath = static_cast(query.getColumn(query.getColumnIndex("sd_file_path"))); - // TODO Rethink this - could hang here for quite a while creating temporary files - if (CreateSiaDriveFile(siaPath, filePath, sdFilePath + ".temp", sdFilePath)) + if (dokanDrive->LockFile(filePath)) { - // TODO Validate response - json response; - SiaCurlError cerror = siaCurl.Post(SString(L"/renter/upload/") + siaPath, { {L"source", filePath} }, response); - if (ApiSuccess(cerror)) + if (CreateSiaDriveFile(siaPath, filePath, sdFilePath + ".temp", sdFilePath)) { - SET_STATUS(UploadStatus::Uploading, UploadToSiaStarted, ModifyUploadStatusFailed) + dokanDrive->UnLockFile(filePath, sdFilePath); + json response; + SiaCurlError cerror = siaCurl.Post(SString(L"/renter/upload/") + siaPath, { {L"source", filePath} }, response); + if (ApiSuccess(cerror)) + { + SET_STATUS(UploadStatus::Uploading, UploadToSiaStarted, ModifyUploadStatusFailed) + } + } + else + { + dokanDrive->UnLockFile(filePath); } } }