1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-18 20:34:39 +01:00

Fix after review

This commit is contained in:
vkrishtal 2014-04-25 08:57:31 +04:00
parent 69b4f9113a
commit 42f62be5b6
4 changed files with 19 additions and 48 deletions

View File

@ -17,6 +17,7 @@
#include "filesystemmusicstorage.h"
#include "core/logging.h"
#include "core/utilities.h"
#include <QDir>
#include <QFile>
@ -50,44 +51,10 @@ bool FilesystemMusicStorage::CopyToStorage(const CopyJob& job) {
}
bool FilesystemMusicStorage::DeleteFromStorage(const DeleteJob& job) {
bool result = false;
QString path = job.metadata_.url().toLocalFile();
QFileInfo fileInfo(path);
if (fileInfo.isDir())
result = RemoveDirectory(path);
return Utilities::RemoveRecursive(path);
else
result = 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;
return QFile::remove(path);
}

View File

@ -30,9 +30,6 @@ class FilesystemMusicStorage : public virtual MusicStorage {
bool CopyToStorage(const CopyJob& job);
bool DeleteFromStorage(const DeleteJob& job);
private:
bool RemoveDirectory(const QString &dirName);
private:
QString root_;
};

View File

@ -219,17 +219,24 @@ QString GetTemporaryFileName() {
return file;
}
void RemoveRecursive(const QString& path) {
bool RemoveRecursive(const QString& path) {
QDir dir(path);
for (const QString& child :
dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Hidden))
RemoveRecursive(path + "/" + child);
dir.entryList(QDir::NoDotAndDotDot | QDir::Dirs | QDir::Hidden)) {
if (!RemoveRecursive(path + "/" + child))
return false;
}
for (const QString& child :
dir.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden))
QFile::remove(path + "/" + child);
dir.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Hidden)) {
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) {

View File

@ -51,7 +51,7 @@ quint64 FileSystemFreeSpace(const QString& path);
QString MakeTempDir(const QString template_name = QString());
QString GetTemporaryFileName();
void RemoveRecursive(const QString& path);
bool RemoveRecursive(const QString& path);
bool CopyRecursive(const QString& source, const QString& destination);
bool Copy(QIODevice* source, QIODevice* destination);