diff --git a/CHANGELOG.md b/CHANGELOG.md index 1481b1cd..f561626b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,8 @@ Thanks to the following contributors who worked on this release: ### Fixed - Fixed AppStream validation issues in `xdg/powertabeditor.metainfo.xml` -- Fixed a bug which could prevent barlines from being deleted +- Fixed a bug which could prevent barlines from being deleted (#496) +- Fixed errors with saving files in the Snap or Flatpak packages (#498) ## [2.0.20] - 2024-11-03 diff --git a/source/app/powertabeditor.cpp b/source/app/powertabeditor.cpp index e2ad63e4..310f4ec8 100644 --- a/source/app/powertabeditor.cpp +++ b/source/app/powertabeditor.cpp @@ -411,7 +411,7 @@ bool PowerTabEditor::saveFile(int doc_index, QString path) try { - myFileFormatManager->exportFile(doc.getScore(), path_str, *format); + myFileFormatManager->exportFile(doc.getScore(), path_str, Paths::getBackupDir(), *format); } catch (const std::exception &e) { diff --git a/source/dialogs/bulkconverterdialog.cpp b/source/dialogs/bulkconverterdialog.cpp index 74b58f56..e970b6f5 100644 --- a/source/dialogs/bulkconverterdialog.cpp +++ b/source/dialogs/bulkconverterdialog.cpp @@ -58,7 +58,7 @@ convertFile(const std::filesystem::path &src, const std::filesystem::path &dst, try { - ffm->exportFile(score, dst, export_format); + ffm->exportFile(score, dst, Paths::getBackupDir(), export_format); } catch (const std::exception &) { diff --git a/source/formats/fileformatmanager.cpp b/source/formats/fileformatmanager.cpp index 0db9bb7f..4d3e7b62 100644 --- a/source/formats/fileformatmanager.cpp +++ b/source/formats/fileformatmanager.cpp @@ -109,12 +109,13 @@ std::string FileFormatManager::exportFileFilter() const return filter; } -void FileFormatManager::exportFile(const Score &score, - const std::filesystem::path &filename, - const FileFormat &format) +void +FileFormatManager::exportFile(const Score &score, const std::filesystem::path &filename, + const std::filesystem::path &backup_folder, const FileFormat &format) { // Write to a temporary file and then swap, to avoid data loss if e.g. the exporter crashes. - std::filesystem::path temp_file = std::filesystem::temp_directory_path() / filename.filename(); + std::filesystem::create_directories(backup_folder); + std::filesystem::path temp_file = backup_folder / filename.filename(); temp_file += ".new"; for (auto &exporter : myExporters) @@ -122,7 +123,13 @@ void FileFormatManager::exportFile(const Score &score, if (exporter->fileFormat() == format) { exporter->save(temp_file, score); - std::filesystem::rename(temp_file, filename); + + // Note that filesystem::rename() doesn't work if the backup folder is on a different + // volume, so just copy. + std::filesystem::copy(temp_file, filename, + std::filesystem::copy_options::overwrite_existing); + std::filesystem::remove(temp_file); + return; } } diff --git a/source/formats/fileformatmanager.h b/source/formats/fileformatmanager.h index 2e8d0539..c9d959d0 100644 --- a/source/formats/fileformatmanager.h +++ b/source/formats/fileformatmanager.h @@ -53,7 +53,7 @@ class FileFormatManager /// Exports the given score to a file. /// @throws std::exception void exportFile(const Score &score, const std::filesystem::path &filename, - const FileFormat &format); + const std::filesystem::path &backup_folder, const FileFormat &format); // Checks to see if there is an importer for the designated extension bool extensionImportSupported(const std::string& extension) const;