Skip to content

Commit

Permalink
Correctly handle the case, when unsynced project is removed from Cache
Browse files Browse the repository at this point in the history
Resolves audacity#6183
  • Loading branch information
crsib committed Apr 17, 2024
1 parent 3b38c69 commit edf6c9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
23 changes: 18 additions & 5 deletions libraries/lib-cloud-audiocom/sync/CloudProjectsDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,26 @@ void CloudProjectsDatabase::RemovePendingSnapshot(
if (!connection)
return;

auto statement = connection->CreateStatement(
"DELETE FROM pending_snapshots WHERE project_id = ? AND snapshot_id = ?");
static const char* queries[] = {
"DELETE FROM pending_snapshots WHERE project_id = ? AND snapshot_id = ?",
"DELETE FROM pending_project_blobs WHERE project_id = ? AND snapshot_id = ?",
"DELETE FROM pending_project_blocks WHERE project_id = ? AND snapshot_id = ?",
};

if (!statement)
return;
auto tx = connection->BeginTransaction("RemovePendingSnapshot");

statement->Prepare(projectId, snapshotId).Run();
for (auto query : queries)
{
auto statement = connection->CreateStatement(query);

if (!statement)
return;

if (!statement->Prepare(projectId, snapshotId).Run().IsOk())
return;
}

tx.Commit();
}

std::vector<PendingSnapshotData>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "SampleBlock.h"
#include "WaveTrack.h"

#include "CodeConversions.h"
#include "DateTimeConversions.h"
#include "FromChars.h"
#include "IResponse.h"
Expand Down Expand Up @@ -214,12 +215,27 @@ class ResumedSnaphotUploadOperation final :

task.Block.Format =
static_cast<sampleFormat>(pendingBlock.BlockSampleFormat);
task.Block.Hash = pendingBlock.BlockHash;
task.Block.Id = pendingBlock.BlockId;
task.Block.Block = sampleBlockFactory->CreateFromId(
task.Block.Format, pendingBlock.BlockId);
task.Block.Hash = pendingBlock.BlockHash;
task.Block.Id = pendingBlock.BlockId;
try
{
task.Block.Block = sampleBlockFactory->CreateFromId(
task.Block.Format, pendingBlock.BlockId);

blockTasks.push_back(std::move(task));
blockTasks.push_back(std::move(task));
}
catch (const FileException& e)
{
// We have failed to resume the upload, local data is missing
CloudProjectsDatabase::Get().RemovePendingSnapshot(
mProjectId, mSnapshotId);
FailSync(
{ SyncResultCode::InternalClientError,
ToUTF8(
XO("Local project data was removed before the sync has completed")
.Translation()) });
return;
}
}

mMissingBlocksUploader = MissingBlocksUploader::Create(
Expand Down

0 comments on commit edf6c9d

Please sign in to comment.