mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
refs #887, support nested directories in comparison
This commit is contained in:
committed by
Mathew Sutcliffe
parent
fce4cb8a4d
commit
96a2b757e7
@@ -100,6 +100,13 @@ namespace BlackMisc
|
|||||||
return QUrl::fromPercentEncoding(directory.toUtf8());
|
return QUrl::fromPercentEncoding(directory.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList CDirectoryUtils::getSubDirectories(const QString &rootDir)
|
||||||
|
{
|
||||||
|
QDir dir(rootDir);
|
||||||
|
if (!dir.exists()) { return QStringList(); }
|
||||||
|
return dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
|
||||||
|
}
|
||||||
|
|
||||||
QSet<QString> CDirectoryUtils::fileNamesToQSet(const QFileInfoList &fileInfoList)
|
QSet<QString> CDirectoryUtils::fileNamesToQSet(const QFileInfoList &fileInfoList)
|
||||||
{
|
{
|
||||||
QSet<QString> sl;
|
QSet<QString> sl;
|
||||||
@@ -136,15 +143,16 @@ namespace BlackMisc
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDirectoryUtils::DirComparison CDirectoryUtils::compareTwoDirectories(const QString &dirSource, const QString &dirTarget)
|
CDirectoryUtils::DirComparison CDirectoryUtils::compareTwoDirectories(const QString &dirSource, const QString &dirTarget, bool nestedDirs)
|
||||||
{
|
{
|
||||||
DirComparison comp;
|
DirComparison comp;
|
||||||
const QDir d1(dirSource);
|
const QDir d1(dirSource);
|
||||||
const QDir d2(dirTarget);
|
const QDir d2(dirTarget);
|
||||||
|
|
||||||
if (!d1.exists() || !d2.exists()) { return comp; }
|
QFileInfoList dSourceList;
|
||||||
const QFileInfoList dSourceList = d1.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
|
QFileInfoList dTargetList;
|
||||||
const QFileInfoList dTargetList = d2.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name);
|
if (d1.exists()) { dSourceList = d1.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); }
|
||||||
|
if (d2.exists()) { dTargetList = d2.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name); }
|
||||||
|
|
||||||
// only names
|
// only names
|
||||||
const QSet<QString> sSourceFiles = CDirectoryUtils::fileNamesToQSet(dSourceList);
|
const QSet<QString> sSourceFiles = CDirectoryUtils::fileNamesToQSet(dSourceList);
|
||||||
@@ -187,9 +195,36 @@ namespace BlackMisc
|
|||||||
comp.newerInSource.insert(source.canonicalFilePath());
|
comp.newerInSource.insert(source.canonicalFilePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nestedDirs)
|
||||||
|
{
|
||||||
|
const QStringList relativeSubdirs = CDirectoryUtils::getSubDirectories(dirSource);
|
||||||
|
if (!relativeSubdirs.isEmpty())
|
||||||
|
{
|
||||||
|
for (const QString relativeSubdir : relativeSubdirs)
|
||||||
|
{
|
||||||
|
const QString sourceSubdir = CFileUtils::appendFilePaths(dirSource, relativeSubdir);
|
||||||
|
const QString targetSubdir = CFileUtils::appendFilePaths(dirTarget, relativeSubdir);
|
||||||
|
const DirComparison subComparison = CDirectoryUtils::compareTwoDirectories(sourceSubdir, targetSubdir, true);
|
||||||
|
comp.insert(subComparison);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
comp.ok = true;
|
comp.ok = true;
|
||||||
return comp;
|
return comp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDirectoryUtils::DirComparison::insert(const CDirectoryUtils::DirComparison &otherComparison)
|
||||||
|
{
|
||||||
|
source += otherComparison.source;
|
||||||
|
missingInSource += otherComparison.missingInSource;
|
||||||
|
missingInTarget += otherComparison.missingInTarget;
|
||||||
|
newerInSource += otherComparison.newerInSource;
|
||||||
|
newerInTarget += otherComparison.newerInTarget;
|
||||||
|
sameNameInSource += otherComparison.sameNameInSource;
|
||||||
|
sameNameInTarget += otherComparison.sameNameInTarget;
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
//! \endcond
|
//! \endcond
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ namespace BlackMisc
|
|||||||
//! Virtually the inverse operation of CDirectoryUtils::normalizedApplicationDirectory
|
//! Virtually the inverse operation of CDirectoryUtils::normalizedApplicationDirectory
|
||||||
static QString decodeNormalizedDirectory(const QString &directory);
|
static QString decodeNormalizedDirectory(const QString &directory);
|
||||||
|
|
||||||
|
//! All sub directories of given dir
|
||||||
|
static QStringList getSubDirectories(const QString &rootDir);
|
||||||
|
|
||||||
//! Result of directory comparison
|
//! Result of directory comparison
|
||||||
struct DirComparison
|
struct DirComparison
|
||||||
{
|
{
|
||||||
@@ -62,10 +65,13 @@ namespace BlackMisc
|
|||||||
QSet<QString> newerInTarget; //!< file in target is newer
|
QSet<QString> newerInTarget; //!< file in target is newer
|
||||||
QSet<QString> sameNameInSource; //!< file exists in source and target, source name
|
QSet<QString> sameNameInSource; //!< file exists in source and target, source name
|
||||||
QSet<QString> sameNameInTarget; //!< file exists in source and target, target name
|
QSet<QString> sameNameInTarget; //!< file exists in source and target, target name
|
||||||
|
|
||||||
|
//! Insert values of another comparison
|
||||||
|
void insert(const DirComparison &otherComparison);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Compare 2 directories (only files, not subdirectories
|
//! Compare 2 directories (only files, but with hierarchy)
|
||||||
static DirComparison compareTwoDirectories(const QString &dirSource, const QString &dirTarget);
|
static DirComparison compareTwoDirectories(const QString &dirSource, const QString &dirTarget, bool nestedDirs);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! Returns the application directory of the calling executable as normalized string.
|
//! Returns the application directory of the calling executable as normalized string.
|
||||||
|
|||||||
Reference in New Issue
Block a user