Add extra safety for overwriting files for filesystem storage

This commit is contained in:
Jonas Kvinge 2020-07-31 21:45:01 +02:00
parent f22133c3c5
commit 53fc2c7c21
1 changed files with 12 additions and 4 deletions

View File

@ -69,8 +69,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
// Copy or move
bool result(true);
if (job.remove_original_) {
result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
if (dest.exists() && !job.overwrite_) {
result = false;
}
else {
result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
}
if ((!cover_dest.exists() || job.overwrite_) && !cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
QFile::rename(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
}
// Remove empty directories.
@ -83,10 +88,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
#endif
}
else {
if (!dest.exists()) {
if (dest.exists() && !job.overwrite_) {
result = false;
}
else {
result = QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
}
if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty() && !cover_dest.exists()) {
if ((!cover_dest.exists() || job.overwrite_) && !cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
QFile::copy(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
}
}