Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117757596
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/file/basicindexingqueue.cpp b/src/file/basicindexingqueue.cpp
index 8850b560..405acf0b 100644
--- a/src/file/basicindexingqueue.cpp
+++ b/src/file/basicindexingqueue.cpp
@@ -1,211 +1,197 @@
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <xapian.h>
#include "basicindexingqueue.h"
#include "fileindexerconfig.h"
#include "util.h"
#include "basicindexingjob.h"
#include "database.h"
#include "filemapping.h"
#include <KDebug>
#include <KMimeType>
#include <QDateTime>
#include <QTimer>
using namespace Baloo;
BasicIndexingQueue::BasicIndexingQueue(Database* db, FileIndexerConfig* config, QObject* parent)
: IndexingQueue(parent)
, m_db(db)
, m_config(config)
{
}
void BasicIndexingQueue::clear()
{
- m_currentFile.clear();
m_paths.clear();
}
void BasicIndexingQueue::clear(const QString& path)
{
QMutableVectorIterator< QPair<FileMapping, UpdateDirFlags> > it(m_paths);
while (it.hasNext()) {
it.next();
if (it.value().first.url().startsWith(path))
it.remove();
}
}
bool BasicIndexingQueue::isEmpty()
{
return m_paths.isEmpty();
}
void BasicIndexingQueue::enqueue(const FileMapping& file)
{
UpdateDirFlags flags;
flags |= UpdateRecursive;
enqueue(file, flags);
}
void BasicIndexingQueue::enqueue(const FileMapping& file, UpdateDirFlags flags)
{
kDebug() << file.url();
m_paths.push(qMakePair(file, flags));
callForNextIteration();
Q_EMIT startedIndexing();
}
void BasicIndexingQueue::processNextIteration()
{
bool processingFile = false;
if (!m_paths.isEmpty()) {
QPair<FileMapping, UpdateDirFlags> pair = m_paths.pop();
processingFile = process(pair.first, pair.second);
}
if (!processingFile)
finishIteration();
}
bool BasicIndexingQueue::process(FileMapping& file, UpdateDirFlags flags)
{
bool startedIndexing = false;
QString mimetype = KMimeType::findByUrl(QUrl::fromLocalFile(file.url()))->name();
bool forced = flags & ForceUpdate;
bool recursive = flags & UpdateRecursive;
bool indexingRequired = shouldIndex(file, mimetype);
QFileInfo info(file.url());
if (info.isDir()) {
if (forced || indexingRequired) {
- m_currentFile = file;
- m_currentMimeType = mimetype;
-
startedIndexing = true;
- index(file);
+ index(file, mimetype);
}
// We don't want to follow system links
if (recursive && !info.isSymLink() && shouldIndexContents(file.url())) {
QDir::Filters dirFilter = QDir::NoDotAndDotDot | QDir::Readable | QDir::Files | QDir::Dirs;
QDirIterator it(file.url(), dirFilter);
while (it.hasNext()) {
m_paths.push(qMakePair(FileMapping(it.next()), flags));
}
}
} else if (info.isFile() && (forced || indexingRequired)) {
- m_currentFile = file;
- m_currentMimeType = mimetype;
-
startedIndexing = true;
- index(file);
+ index(file, mimetype);
}
return startedIndexing;
}
bool BasicIndexingQueue::shouldIndex(FileMapping& file, const QString& mimetype) const
{
bool shouldBeIndexed = m_config->shouldBeIndexed(file.url());
if (!shouldBeIndexed)
return false;
bool shouldIndexType = m_config->shouldMimeTypeBeIndexed(mimetype);
if (!shouldIndexType)
return false;
QFileInfo fileInfo(file.url());
if (!fileInfo.exists())
return false;
if (!file.fetch(m_db->sqlDatabase())) {
return true;
}
try {
m_db->xapianDatabase()->reopen();
Xapian::Document doc = m_db->xapianDatabase()->get_document(file.id());
Xapian::TermIterator it = doc.termlist_begin();
it.skip_to("DT_M");
if (it == doc.termlist_end()) {
return true;
}
// A folders mtime is updated when a new file is added / removed / renamed
// we don't really need to reindex a folder when that happens
// In fact, we never need to reindex a folder
if (mimetype == QLatin1String("inode/directory"))
return false;
// The 4 is for "DT_M"
const QString str = QString::fromStdString(*it).mid(4);
const QDateTime mtime = QDateTime::fromString(str, Qt::ISODate);
if (mtime != fileInfo.lastModified())
return true;
}
catch (const Xapian::DocNotFoundError&) {
return true;
}
return false;
}
bool BasicIndexingQueue::shouldIndexContents(const QString& dir)
{
return m_config->shouldFolderBeIndexed(dir);
}
-void BasicIndexingQueue::index(const FileMapping& file)
+void BasicIndexingQueue::index(const FileMapping& file, const QString& mimetype)
{
kDebug() << file.id() << file.url();
- Q_EMIT beginIndexingFile(file);
- BasicIndexingJob job(&m_db->sqlDatabase(), file, m_currentMimeType);
+ BasicIndexingJob job(&m_db->sqlDatabase(), file, mimetype);
if (job.index()) {
Q_EMIT newDocument(job.id(), job.document());
}
QTimer::singleShot(0, this, SLOT(slotIndexingFinished()));
}
void BasicIndexingQueue::slotIndexingFinished()
{
- FileMapping file = m_currentFile;
- m_currentFile.clear();
- m_currentMimeType.clear();
-
- Q_EMIT endIndexingFile(file);
-
// Continue the queue
finishIteration();
}
diff --git a/src/file/basicindexingqueue.h b/src/file/basicindexingqueue.h
index 6886d6f7..c184f4c9 100644
--- a/src/file/basicindexingqueue.h
+++ b/src/file/basicindexingqueue.h
@@ -1,130 +1,122 @@
/*
<one line to give the library's name and an idea of what it does.>
Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BASICINDEXINGQUEUE_H
#define BASICINDEXINGQUEUE_H
#include "indexingqueue.h"
#include "filemapping.h"
#include <KJob>
#include <QStack>
#include <xapian.h>
class Database;
namespace Baloo
{
class FileIndexerConfig;
enum UpdateDirFlag {
/**
* No flags, only used to make code more readable
*/
NoUpdateFlags = 0x0,
/**
* The folder should be updated recursive
*/
UpdateRecursive = 0x1,
/**
* The folder has been scheduled to update by the
* update system, not by a call to updateDir
*/
AutoUpdateFolder = 0x2,
/**
* The files in the folder should be updated regardless
* of their state.
*/
ForceUpdate = 0x4
};
Q_DECLARE_FLAGS(UpdateDirFlags, UpdateDirFlag)
/**
* This class represents a simple queue that iterates over the file system tree
* and indexes each file which meets certain critera. The indexing performed by this
* queue is very basic. It just pushes the mimetype, url and stat results of the file.
*/
class BasicIndexingQueue: public IndexingQueue
{
Q_OBJECT
public:
explicit BasicIndexingQueue(Database* db, FileIndexerConfig* config, QObject* parent = 0);
virtual bool isEmpty();
Q_SIGNALS:
- void beginIndexingFile(const Baloo::FileMapping& file);
- void endIndexingFile(const Baloo::FileMapping& file);
-
void newDocument(unsigned id, Xapian::Document doc);
public Q_SLOTS:
void enqueue(const FileMapping& file);
void enqueue(const FileMapping& file, UpdateDirFlags flags);
void clear();
void clear(const QString& path);
protected:
virtual void processNextIteration();
private Q_SLOTS:
void slotIndexingFinished();
private:
/**
* This method does not need to be synchronous. The indexing operation may be started
* and on completion, the finishedIndexing method should be called
*/
- void index(const FileMapping& file);
+ void index(const FileMapping& file, const QString& mimetype);
bool shouldIndex(FileMapping& file, const QString& mimetype) const;
bool shouldIndexContents(const QString& dir);
/**
* Check if the \p path needs to be indexed based on the \p flags
* and the path. If it needs to be indexed, then start indexing
* it.
*
* \return \c true the path is being indexed
* \return \c false the path did not meet the criteria
*/
bool process(FileMapping& file, UpdateDirFlags flags);
QStack< QPair<FileMapping, UpdateDirFlags> > m_paths;
- FileMapping m_currentFile;
- QString m_currentMimeType;
-
- UpdateDirFlags m_currentFlags;
-
Database* m_db;
FileIndexerConfig* m_config;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(Baloo::UpdateDirFlags)
#endif // BASICINDEXINGQUEUE_H
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 9:19 AM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823433
Default Alt Text
(10 KB)
Attached To
Mode
rKB baloo
Attached
Detach File
Event Timeline