Skip to content

Commit 40322b0

Browse files
authored
Merge pull request #12 from kryksyh/bugfixes
Bugfixes
2 parents cd7654c + edd0a14 commit 40322b0

8 files changed

Lines changed: 52 additions & 30 deletions

File tree

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,12 @@ build/**
3636
out/**
3737
.venv/**
3838
CMakeUserPresets.json
39+
40+
# Audacity files
41+
42+
*.aup3
43+
*.aup4
44+
*.aup3-shm
45+
*.aup3-wal
46+
*.aup4-shm
47+
*.aup4-wal

src/AudacityDatabase.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ AudacityDatabase::AudacityDatabase(
132132
}, true);
133133
}
134134

135+
AudacityDatabase::~AudacityDatabase()
136+
{
137+
mDatabase.reset();
138+
removeJournalFiles(mReadOnly ? mProjectPath : mWritablePath);
139+
}
140+
135141
void AudacityDatabase::reopenReadonlyAsWritable()
136142
{
137143
if (!mReadOnly)
@@ -466,22 +472,26 @@ void AudacityDatabase::extractTrack(
466472
waveFile.writeFile();
467473
}
468474

469-
void AudacityDatabase::removeOldFiles()
475+
void AudacityDatabase::removeJournalFiles(const std::filesystem::path& dbPath)
470476
{
471-
if (std::filesystem::exists(mWritablePath))
472-
{
473-
std::filesystem::remove(mWritablePath);
477+
auto walFile = dbPath;
478+
walFile.replace_extension("aup3-wal");
474479

475-
auto walFile = mWritablePath;
476-
walFile.replace_extension("aup3-wal");
480+
if (std::filesystem::exists(walFile))
481+
std::filesystem::remove(walFile);
477482

478-
if (std::filesystem::exists(walFile))
479-
std::filesystem::remove(walFile);
483+
auto shmFile = dbPath;
484+
shmFile.replace_extension("aup3-shm");
480485

481-
auto shmFile = mWritablePath;
482-
shmFile.replace_extension("aup3-shm");
486+
if (std::filesystem::exists(shmFile))
487+
std::filesystem::remove(shmFile);
488+
}
483489

484-
if (std::filesystem::exists(shmFile))
485-
std::filesystem::remove(shmFile);
490+
void AudacityDatabase::removeOldFiles()
491+
{
492+
if (std::filesystem::exists(mWritablePath))
493+
{
494+
std::filesystem::remove(mWritablePath);
495+
removeJournalFiles(mWritablePath);
486496
}
487497
}

src/AudacityDatabase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class AudacityDatabase final
2424
public:
2525
explicit AudacityDatabase(
2626
const std::filesystem::path& path, RecoveryConfig recoveryConfig);
27+
~AudacityDatabase();
2728

2829
void reopenReadonlyAsWritable();
2930
void recoverDatabase();
@@ -43,6 +44,7 @@ class AudacityDatabase final
4344
void extractTrack(SampleFormat format, int32_t sampleRate, bool asStereo);
4445

4546
private:
47+
static void removeJournalFiles(const std::filesystem::path& dbPath);
4648
void removeOldFiles();
4749

4850
std::unique_ptr<SQLite::Database> mDatabase;

src/BinaryXMLConverter.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,10 @@ class IdsLookup final
281281
public:
282282
void store(uint16_t index, std::string value)
283283
{
284-
const auto size = mIds.size();
284+
if (index >= mIds.size())
285+
mIds.resize(index + 1);
285286

286-
if (index == size)
287-
mIds.push_back(std::move(value));
288-
else
289-
{
290-
if ((index + 1) < size)
291-
mIds.resize(index);
292-
293-
mIds[index] = std::move(value);
294-
}
287+
mIds[index] = std::move(value);
295288
}
296289

297290
std::string_view get(uint16_t index)

src/Buffer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Buffer::read(void* data, size_t offset, size_t size) const noexcept
8686
offset = 0;
8787
bytesLeft -= chunkSize;
8888
outPtr += chunkSize;
89+
++chunk;
8990
}
9091

9192
return size;

src/Buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ class Buffer final
4848
return 0;
4949

5050
const size_t chunkIndex = offset / BUFFER_SIZE;
51-
offset = offset - BUFFER_SIZE * chunkIndex;
51+
const size_t chunkOffset = offset - BUFFER_SIZE * chunkIndex;
5252

53-
if (BUFFER_SIZE < (offset + size))
53+
if (BUFFER_SIZE < (chunkOffset + size))
5454
return read(&data, offset, size);
5555

56-
const void* ptr = mChunks[chunkIndex].data() + offset;
56+
const void* ptr = mChunks[chunkIndex].data() + chunkOffset;
5757

5858
data = *static_cast<const T*>(ptr);
5959

src/ProjectModel.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,22 @@ void AudacityProject::removeUnusedBlocks()
483483

484484
readBlocksList.reset();
485485

486-
std::set<int64_t> orphanedBlocks;
486+
std::set<int64_t> usedBlocks;
487487

488-
for (const auto block : mWaveBlocks)
488+
for (const auto& block : mWaveBlocks)
489489
{
490490
if (block.isSilence())
491491
continue;
492492

493-
if (availableBlocks.count(block.getBlockId()) == 0)
494-
orphanedBlocks.emplace(block.getBlockId());
493+
usedBlocks.emplace(block.getBlockId());
494+
}
495+
496+
std::set<int64_t> orphanedBlocks;
497+
498+
for (auto blockId : availableBlocks)
499+
{
500+
if (usedBlocks.count(blockId) == 0)
501+
orphanedBlocks.emplace(blockId);
495502
}
496503

497504
mDb.reopenReadonlyAsWritable();

src/XMLHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void GetAttributeValue(const AttributeValue& attr, Ret& result)
5555
{
5656
if constexpr (std::is_same_v<Ret, bool>)
5757
{
58-
result = arg == "true" || arg == "0";
58+
result = arg == "true" || arg == "1";
5959
}
6060
else if constexpr (std::is_floating_point_v<Ret>)
6161
{

0 commit comments

Comments
 (0)