@@ -92,7 +92,8 @@ void DeleteFiles::ProcessSomeFiles() {
|
||||
if (progress_ >= songs_.count()) {
|
||||
task_manager_->SetTaskProgress(task_id_, progress_, songs_.count());
|
||||
|
||||
storage_->FinishCopy(songs_with_errors_.isEmpty());
|
||||
QString error_text;
|
||||
storage_->FinishCopy(songs_with_errors_.isEmpty(), error_text);
|
||||
|
||||
task_manager_->SetTaskFinished(task_id_);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
FilesystemMusicStorage::FilesystemMusicStorage(const Song::Source source, const QString &root, const std::optional<int> collection_directory_id) : source_(source), root_(root), collection_directory_id_(collection_directory_id) {}
|
||||
|
||||
bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
||||
bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job, QString &error_text) {
|
||||
|
||||
const QFileInfo src = QFileInfo(job.source_);
|
||||
const QFileInfo dest = QFileInfo(root_ + "/" + job.destination_);
|
||||
@@ -54,7 +54,8 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
||||
// Create directories as required
|
||||
QDir dir;
|
||||
if (!dir.mkpath(dest.absolutePath())) {
|
||||
qLog(Warning) << "Failed to create directory" << dest.dir().absolutePath();
|
||||
error_text = QObject::tr("Failed to create directory %1.").arg(dest.dir().absolutePath());
|
||||
qLog(Error) << error_text;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,10 +66,12 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
||||
}
|
||||
|
||||
// Copy or move
|
||||
bool result(true);
|
||||
bool result = true;
|
||||
if (job.remove_original_) {
|
||||
if (dest.exists() && !job.overwrite_) {
|
||||
result = false;
|
||||
error_text = QObject::tr("Destination file %1 exists, but not allowed to overwrite.").arg(dest.absoluteFilePath());
|
||||
qLog(Error) << error_text;
|
||||
}
|
||||
else {
|
||||
result = QFile::rename(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
@@ -86,9 +89,15 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob &job) {
|
||||
else {
|
||||
if (dest.exists() && !job.overwrite_) {
|
||||
result = false;
|
||||
error_text = QObject::tr("Destination file %1 exists, but not allowed to overwrite").arg(dest.absoluteFilePath());
|
||||
qLog(Error) << error_text;
|
||||
}
|
||||
else {
|
||||
result = QFile::copy(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
if (!result) {
|
||||
error_text = QObject::tr("Could not copy file %1 to %2.").arg(src.absoluteFilePath(), dest.absoluteFilePath());
|
||||
qLog(Error) << error_text;
|
||||
}
|
||||
}
|
||||
if ((!cover_dest.exists() || job.overwrite_) && !cover_src.filePath().isEmpty() && !cover_dest.filePath().isEmpty()) {
|
||||
QFile::copy(cover_src.absoluteFilePath(), cover_dest.absoluteFilePath());
|
||||
|
||||
@@ -39,7 +39,7 @@ class FilesystemMusicStorage : public virtual MusicStorage {
|
||||
QString LocalPath() const override { return root_; }
|
||||
std::optional<int> collection_directory_id() const override { return collection_directory_id_; }
|
||||
|
||||
bool CopyToStorage(const CopyJob &job) override;
|
||||
bool CopyToStorage(const CopyJob &job, QString &error_text) override;
|
||||
bool DeleteFromStorage(const DeleteJob &job) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -89,12 +89,12 @@ class MusicStorage {
|
||||
virtual bool GetSupportedFiletypes(QList<Song::FileType> *ret) { Q_UNUSED(ret); return true; }
|
||||
|
||||
virtual bool StartCopy(QList<Song::FileType> *supported_types) { Q_UNUSED(supported_types); return true; }
|
||||
virtual bool CopyToStorage(const CopyJob &job) = 0;
|
||||
virtual void FinishCopy(bool success) { Q_UNUSED(success); }
|
||||
virtual bool CopyToStorage(const CopyJob &job, QString &error_text) = 0;
|
||||
virtual bool FinishCopy(bool success, QString &error_text) { Q_UNUSED(error_text); return success; }
|
||||
|
||||
virtual void StartDelete() {}
|
||||
virtual bool DeleteFromStorage(const DeleteJob &job) = 0;
|
||||
virtual void FinishDelete(bool success) { Q_UNUSED(success); }
|
||||
virtual bool FinishDelete(bool success, QString &error_text) { Q_UNUSED(error_text); return success; }
|
||||
|
||||
virtual void Eject() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user