Add extra safety for overwriting files for filesystem storage
This commit is contained in:
@@ -69,8 +69,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
|||||||
// Copy or move
|
// Copy or move
|
||||||
bool result(true);
|
bool result(true);
|
||||||
if (job.remove_original_) {
|
if (job.remove_original_) {
|
||||||
result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
|
if (dest.exists() && !job.overwrite_) {
|
||||||
if (!cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
|
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());
|
QFile::rename(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
|
||||||
}
|
}
|
||||||
// Remove empty directories.
|
// Remove empty directories.
|
||||||
@@ -83,10 +88,13 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!dest.exists()) {
|
if (dest.exists() && !job.overwrite_) {
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
result = QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
|
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());
|
QFile::copy(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user