Skip to content

Commit 9989a50

Browse files
Merge pull request #33311 from RomanPudashkin/fix_audio_export_cancel_470
[4.7.0] Fix #33259: fix audio export cancellation
2 parents f5a7a58 + bb9d91b commit 9989a50

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/framework/global/io/internal/filesystem.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,14 @@ Ret FileSystem::removeFile(const io::path_t& path)
317317
QFile file(path.toQString());
318318
if (!file.remove()) {
319319
// Read-only files prevent directory deletion on Windows, retry with Write permission.
320-
LOGW() << "Failed to delete file. Setting write permission and trying again...";
320+
LOGW() << "Failed to delete file: " << file.errorString()
321+
<< "\nSetting write permission and trying again...";
321322
if (!file.setPermissions(file.permissions() | QFile::WriteUser)) {
322-
LOGE() << "Failed to set write permission for file";
323+
LOGE() << "Failed to set write permission for file: " << file.errorString();
323324
return make_ret(Err::FSRemoveError);
324325
}
325326
if (!file.remove()) {
326-
LOGE() << "Second delete attempt failed";
327+
LOGE() << "Second delete attempt failed: " << file.errorString();
327328
return make_ret(Err::FSRemoveError);
328329
}
329330

src/importexport/audioexport/internal/abstractaudiowriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Ret AbstractAudioWriter::writeList(const INotationPtrList&, io::IODevice&, const
8080
void AbstractAudioWriter::abort()
8181
{
8282
playback()->abortSavingAllSoundTracks();
83+
m_writeRet = make_ret(Ret::Code::Cancel);
8384
m_isCompleted = true;
8485
}
8586

src/project/internal/exportprojectscenario.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,16 @@ Ret ExportProjectScenario::doExportLoop(const muse::io::path_t& scorePath, std::
418418

419419
if (!ret || outputFile.hasError()) {
420420
if (ret.code() == static_cast<int>(Ret::Code::Cancel)) {
421-
fileSystem()->remove(scorePath);
421+
// On Windows, remove() may fail immediately after close()
422+
// because the file lock has not been released yet
423+
for (int i = 0; i < 10; ++i) {
424+
if (fileSystem()->remove(scorePath)) {
425+
return ret;
426+
}
427+
428+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
429+
}
430+
422431
return ret;
423432
}
424433

0 commit comments

Comments
 (0)