23 #include "fileutils.h" 26 #include <QCryptographicHash> 27 #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))
47 static const int SANITY_LOOP_LIMIT = 1000;
48 QFileInfo fileInfo(QDir::cleanPath(path));
49 for (
int i = 0; i < SANITY_LOOP_LIMIT; ++i)
51 if (fileInfo.filePath().endsWith(
"/.."))
53 if (fileInfo.exists() || fileInfo.isRoot())
54 return fileInfo.filePath();
55 fileInfo = QDir::cleanPath(fileInfo.filePath() +
"/..");
60 Qt::CaseSensitivity FileUtils::comparisonSensitivity()
62 #if defined(Q_OS_WIN32) 63 return Qt::CaseInsensitive;
65 return Qt::CaseSensitive;
71 for (
const QString &candidate : candidates)
73 if (QFileInfo(candidate) == QFileInfo(path))
80 const QStringList &nameFilters)
82 QDirIterator it(dirPath, nameFilters, QDir::Files);
83 bool bAllSuccess =
true;
86 QString path = it.next();
91 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.