mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-25 03:12:56 +00:00
Revert "rework QPollingFileSystemWatcherEngine to use QFileInfo for files"
QFileInfo equal operator does not compare all attributes
This reverts commit 9812469490
.
This commit is contained in:
parent
61e0a23d43
commit
0e92ef89b9
1 changed files with 47 additions and 48 deletions
|
@ -57,7 +57,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
class DirInfo
|
class FileInfo
|
||||||
{
|
{
|
||||||
uint ownerId;
|
uint ownerId;
|
||||||
uint groupId;
|
uint groupId;
|
||||||
|
@ -66,14 +66,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DirInfo()
|
FileInfo(const QFileInfo &fileInfo)
|
||||||
: ownerId(-1),
|
|
||||||
groupId(-1),
|
|
||||||
permissions(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DirInfo(const QFileInfo &fileInfo)
|
|
||||||
: ownerId(fileInfo.ownerId()),
|
: ownerId(fileInfo.ownerId()),
|
||||||
groupId(fileInfo.groupId()),
|
groupId(fileInfo.groupId()),
|
||||||
permissions(fileInfo.permissions()),
|
permissions(fileInfo.permissions()),
|
||||||
|
@ -83,9 +76,9 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
|
||||||
entries = fileInfo.absoluteDir().entryList(QDir::AllEntries);
|
entries = fileInfo.absoluteDir().entryList(QDir::AllEntries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DirInfo &operator=(const QFileInfo &fileInfo)
|
FileInfo &operator=(const QFileInfo &fileInfo)
|
||||||
{
|
{
|
||||||
*this = DirInfo(fileInfo);
|
*this = FileInfo(fileInfo);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +93,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<QString, QFileInfo> files;
|
QHash<QString, FileInfo> files, directories;
|
||||||
QHash<QString, DirInfo> directories;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QPollingFileSystemWatcherEngine();
|
QPollingFileSystemWatcherEngine();
|
||||||
|
@ -122,29 +114,31 @@ QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine()
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths,
|
QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths,
|
||||||
QStringList *filepaths,
|
QStringList *files,
|
||||||
QStringList *directorypaths)
|
QStringList *directories)
|
||||||
{
|
{
|
||||||
QStringList p = paths;
|
QStringList p = paths;
|
||||||
foreach (const QString &path, p) {
|
QMutableListIterator<QString> it(p);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QString path = it.next();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!fi.exists())
|
if (!fi.exists())
|
||||||
continue;
|
continue;
|
||||||
if (fi.isDir()) {
|
if (fi.isDir()) {
|
||||||
if (!directorypaths->contains(path))
|
if (!directories->contains(path))
|
||||||
directorypaths->append(path);
|
directories->append(path);
|
||||||
if (!path.endsWith(QLatin1Char('/')))
|
if (!path.endsWith(QLatin1Char('/')))
|
||||||
fi = QFileInfo(path + QLatin1Char('/'));
|
fi = QFileInfo(path + QLatin1Char('/'));
|
||||||
directories.insert(path, fi);
|
this->directories.insert(path, fi);
|
||||||
} else {
|
} else {
|
||||||
if (!filepaths->contains(path))
|
if (!files->contains(path))
|
||||||
filepaths->append(path);
|
files->append(path);
|
||||||
files.insert(path, fi);
|
this->files.insert(path, fi);
|
||||||
}
|
}
|
||||||
p.removeAll(path);
|
it.remove();
|
||||||
}
|
}
|
||||||
if ((!files.isEmpty() ||
|
if ((!this->files.isEmpty() ||
|
||||||
!directories.isEmpty()) &&
|
!this->directories.isEmpty()) &&
|
||||||
!timer.isActive()) {
|
!timer.isActive()) {
|
||||||
timer.start(PollingInterval);
|
timer.start(PollingInterval);
|
||||||
}
|
}
|
||||||
|
@ -152,21 +146,23 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths,
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &paths,
|
QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &paths,
|
||||||
QStringList *filepaths,
|
QStringList *files,
|
||||||
QStringList *directorypaths)
|
QStringList *directories)
|
||||||
{
|
{
|
||||||
QStringList p = paths;
|
QStringList p = paths;
|
||||||
foreach (const QString &path, p) {
|
QMutableListIterator<QString> it(p);
|
||||||
if (directories.remove(path)) {
|
while (it.hasNext()) {
|
||||||
directorypaths->removeAll(path);
|
QString path = it.next();
|
||||||
p.removeAll(path);
|
if (this->directories.remove(path)) {
|
||||||
} else if (files.remove(path)) {
|
directories->removeAll(path);
|
||||||
filepaths->removeAll(path);
|
it.remove();
|
||||||
p.removeAll(path);
|
} else if (this->files.remove(path)) {
|
||||||
|
files->removeAll(path);
|
||||||
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (files.isEmpty() &&
|
if (this->files.isEmpty() &&
|
||||||
directories.isEmpty()) {
|
this->directories.isEmpty()) {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
@ -174,33 +170,36 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path
|
||||||
|
|
||||||
void QPollingFileSystemWatcherEngine::timeout()
|
void QPollingFileSystemWatcherEngine::timeout()
|
||||||
{
|
{
|
||||||
foreach (const QString &path, files.keys()) {
|
QMutableHashIterator<QString, FileInfo> fit(files);
|
||||||
const QFileInfo value = files.value(path);
|
while (fit.hasNext()) {
|
||||||
|
QHash<QString, FileInfo>::iterator x = fit.next();
|
||||||
|
QString path = x.key();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
files.remove(path);
|
fit.remove();
|
||||||
emit fileChanged(path, true);
|
emit fileChanged(path, true);
|
||||||
} else if (value != fi) {
|
} else if (x.value() != fi) {
|
||||||
files.insert(path, fi);
|
x.value() = fi;
|
||||||
emit fileChanged(path, false);
|
emit fileChanged(path, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QMutableHashIterator<QString, FileInfo> dit(directories);
|
||||||
foreach (const QString &path, directories.keys()) {
|
while (dit.hasNext()) {
|
||||||
const DirInfo value = files.value(path);
|
QHash<QString, FileInfo>::iterator x = dit.next();
|
||||||
|
QString path = x.key();
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!path.endsWith(QLatin1Char('/')))
|
if (!path.endsWith(QLatin1Char('/')))
|
||||||
fi = QFileInfo(path + QLatin1Char('/'));
|
fi = QFileInfo(path + QLatin1Char('/'));
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
directories.remove(path);
|
dit.remove();
|
||||||
emit directoryChanged(path, true);
|
emit directoryChanged(path, true);
|
||||||
} else if (value != fi) {
|
} else if (x.value() != fi) {
|
||||||
fi.refresh();
|
fi.refresh();
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
directories.remove(path);
|
dit.remove();
|
||||||
emit directoryChanged(path, true);
|
emit directoryChanged(path, true);
|
||||||
} else {
|
} else {
|
||||||
directories.insert(path, DirInfo(fi));
|
x.value() = fi;
|
||||||
emit directoryChanged(path, false);
|
emit directoryChanged(path, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue