FileIteratorWrapper: refactor setPath()

Only call setPath() in hasNext(), the latter is called before any other
member method, and setPath() is guarded by a bool to only run a single
time.

Split some code to a helper function, which will be reused when porting
to new QAFEngine API.

Change-Id: Ibda0ede18593a3a20729b31e03e994ad2de126de
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
(cherry picked from commit ad446d5689)
This commit is contained in:
Ahmad Samir
2024-03-06 15:48:07 +02:00
parent 28c67fca0f
commit 1e05c45d8f

View File

@@ -47,7 +47,6 @@ public:
if (m_status == State::Ended) if (m_status == State::Ended)
return QString(); return QString();
setPath();
checkStatus(); checkStatus();
if (m_status == State::BaseIteratorEnd) { if (m_status == State::BaseIteratorEnd) {
@@ -75,7 +74,6 @@ public:
if (m_status == State::Ended) if (m_status == State::Ended)
return FilePath::specialRootPath(); return FilePath::specialRootPath();
setPath();
checkStatus(); checkStatus();
return m_baseIterator->currentFileName(); return m_baseIterator->currentFileName();
} }
@@ -83,22 +81,26 @@ public:
{ {
if (m_status == State::Ended) if (m_status == State::Ended)
return QFileInfo(FilePath::specialRootPath()); return QFileInfo(FilePath::specialRootPath());
setPath();
checkStatus(); checkStatus();
return m_baseIterator->currentFileInfo(); return m_baseIterator->currentFileInfo();
} }
private: private:
QString setStatus() const
{
// path() can be "/somedir/.." so we need to clean it first.
// We only need QDir::cleanPath here, as the path is always
// a fs engine path and will not contain scheme:// etc.
QString p = QDir::cleanPath(path());
if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0)
m_status = State::IteratingRoot;
return p;
}
void setPath() const void setPath() const
{ {
if (!m_hasSetPath) { if (!m_hasSetPath) {
// path() can be "/somedir/.." so we need to clean it first. const QString &p = setStatus();
// We only need QDir::cleanPath here, as the path is always
// a fs engine path and will not contain scheme:// etc.
const QString p = QDir::cleanPath(path());
if (p.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0)
m_status = State::IteratingRoot;
((*m_baseIterator).*get(QAFEITag()))(p); ((*m_baseIterator).*get(QAFEITag()))(p);
m_hasSetPath = true; m_hasSetPath = true;
} }