mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-19 21:04:08 +01:00
Fix after review
This commit is contained in:
parent
69b4f9113a
commit
42f62be5b6
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "filesystemmusicstorage.h"
|
#include "filesystemmusicstorage.h"
|
||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
|
#include "core/utilities.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -50,44 +51,10 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob& job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob& job) {
|
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob& job) {
|
||||||
bool result = false;
|
QString path = job.metadata_.url().toLocalFile();
|
||||||
|
|
||||||
QString path = job.metadata_.url().toLocalFile();
|
|
||||||
QFileInfo fileInfo(path);
|
QFileInfo fileInfo(path);
|
||||||
if (fileInfo.isDir())
|
if (fileInfo.isDir())
|
||||||
result = RemoveDirectory(path);
|
return Utilities::RemoveRecursive(path);
|
||||||
else
|
else
|
||||||
result = QFile::remove(path);
|
return QFile::remove(path);
|
||||||
|
}
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FilesystemMusicStorage::RemoveDirectory(const QString& dirName) {
|
|
||||||
bool result = true;
|
|
||||||
QDir dir(dirName);
|
|
||||||
|
|
||||||
if (dir.exists(dirName)) {
|
|
||||||
auto fileInfoList = dir.entryInfoList(QDir::NoDotAndDotDot
|
|
||||||
| QDir::System
|
|
||||||
| QDir::Hidden
|
|
||||||
| QDir::AllDirs
|
|
||||||
| QDir::Files
|
|
||||||
, QDir::DirsFirst);
|
|
||||||
|
|
||||||
for (auto info : fileInfoList) {
|
|
||||||
// remove subdirectories too
|
|
||||||
if (info.isDir()) {
|
|
||||||
result = RemoveDirectory(info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = QFile::remove(info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = dir.rmdir(dirName);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
@ -30,9 +30,6 @@ class FilesystemMusicStorage : public virtual MusicStorage {
|
|||||||
bool CopyToStorage(const CopyJob& job);
|
bool CopyToStorage(const CopyJob& job);
|
||||||
bool DeleteFromStorage(const DeleteJob& job);
|
bool DeleteFromStorage(const DeleteJob& job);
|
||||||
|
|
||||||
private:
|
|
||||||
bool RemoveDirectory(const QString &dirName);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString root_;
|
QString root_;
|
||||||
};
|
};
|
||||||
|
@ -219,17 +219,24 @@ QString GetTemporaryFileName() {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveRecursive(const QString& path) {
|
bool RemoveRecursive(const QString& path) {
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
for (const QString& child :
|
for (const QString& child :
|
||||||
dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Hidden))
|
dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Hidden)) {
|
||||||
RemoveRecursive(path + "/" + child);
|
if (!RemoveRecursive(path + "/" + child))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (const QString& child :
|
for (const QString& child :
|
||||||
dir.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden))
|
dir.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden)) {
|
||||||
QFile::remove(path + "/" + child);
|
if (!QFile::remove(path + "/" + child))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
dir.rmdir(path);
|
if (!dir.rmdir(path))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CopyRecursive(const QString& source, const QString& destination) {
|
bool CopyRecursive(const QString& source, const QString& destination) {
|
||||||
|
@ -51,7 +51,7 @@ quint64 FileSystemFreeSpace(const QString& path);
|
|||||||
|
|
||||||
QString MakeTempDir(const QString template_name = QString());
|
QString MakeTempDir(const QString template_name = QString());
|
||||||
QString GetTemporaryFileName();
|
QString GetTemporaryFileName();
|
||||||
void RemoveRecursive(const QString& path);
|
bool RemoveRecursive(const QString& path);
|
||||||
bool CopyRecursive(const QString& source, const QString& destination);
|
bool CopyRecursive(const QString& source, const QString& destination);
|
||||||
bool Copy(QIODevice* source, QIODevice* destination);
|
bool Copy(QIODevice* source, QIODevice* destination);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user