23 #include "fileutils.h" 25 #include <QCryptographicHash> 26 #include <QDirIterator> 30 QByteArray FileUtils::md5(
const QString &path)
33 if (f.open(QIODevice::ReadOnly))
35 QCryptographicHash hash(QCryptographicHash::Md5);
36 QByteArray chunk = f.read(1024 * 1024);
37 for (; !chunk.isEmpty(); chunk = f.read(1024 * 1024))
49 static const int SANITY_LOOP_LIMIT = 1000;
50 QFileInfo fileInfo(QDir::cleanPath(path));
51 for (
int i = 0; i < SANITY_LOOP_LIMIT; ++i)
53 if (fileInfo.filePath().endsWith(
"/.."))
55 if (fileInfo.exists() || fileInfo.isRoot())
56 return fileInfo.filePath();
57 fileInfo = QDir::cleanPath(fileInfo.filePath() +
"/..");
62 Qt::CaseSensitivity FileUtils::comparisonSensitivity()
64 #if defined(Q_OS_WIN32) 65 return Qt::CaseInsensitive;
67 return Qt::CaseSensitive;
73 foreach (
const QString &candidate, candidates)
75 if (QFileInfo(candidate) == QFileInfo(path))
84 const QStringList & nameFilters)
86 QDirIterator it(dirPath, nameFilters, QDir::Files);
87 bool bAllSuccess =
true;
90 QString path = it.next();
95 gLog << Log::tr(
"Failed to remove: %1").arg(path);
static bool containsPath(const QStringList &candidates, const QString &path)
Uses QFileInfo::operator== to see if 'path' is on 'candidates' list.
static bool rmAllFiles(const QString &dirPath, const QStringList &nameFilters=QStringList())
Deletes all files in specified directory.
static QString cdUpUntilExists(QString path)
Moves upwards the path until it finds the path that exists.