Mercurial > dedupe
comparison MemoryDBLink.cpp @ 7:d6fdca3bf24e
Make sure everything works for MemoryDBLink.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Wed, 22 Aug 2012 01:07:06 +0200 |
| parents | aae83c0a771d |
| children | b9515dc35fe4 |
comparison
equal
deleted
inserted
replaced
| 6:7ebdd2373ea4 | 7:d6fdca3bf24e |
|---|---|
| 1 #include "MemoryDBLink.hpp" | 1 #include "MemoryDBLink.hpp" |
| 2 | 2 |
| 3 #include <QtCore/QStringList> | 3 #include <QtCore/QStringList> |
| 4 | 4 |
| 5 void MemoryDBLink::addFile(const QString& path, qint64 size, const QDateTime& dtime, const QCryptographicHash& hash) | 5 void MemoryDBLink::addFile(const QString& path, qint64 size, const QDateTime& dtime, const QByteArray& hash) |
| 6 { | 6 { |
| 7 addFile(DBInfo(path, size, dtime, hash.result())); | 7 addFile(DBInfo(path, size, dtime, hash)); |
| 8 } | 8 } |
| 9 | 9 |
| 10 bool MemoryDBLink::tryAddFile(const DBInfo& dbinfo) | 10 bool MemoryDBLink::tryAddFile(const DBInfo& dbinfo) |
| 11 { | 11 { |
| 12 QMap<QString, QSharedPointer<DBInfo> >::iterator pos; | 12 QMap<QString, QSharedPointer<DBInfo> >::iterator pos; |
| 33 list << info->serialize(); | 33 list << info->serialize(); |
| 34 } | 34 } |
| 35 return list; | 35 return list; |
| 36 } | 36 } |
| 37 | 37 |
| 38 const QList<QSharedPointer<FileDBLink::DBInfo> > MemoryDBLink::values() const | 38 const QList<QSharedPointer<FileDBLink::DBInfo> > MemoryDBLink::values(const QString& prefix) const |
| 39 { | 39 { |
| 40 return entries.values(); | 40 if (prefix.size() == 0) |
| 41 return entries.values(); | |
| 42 | |
| 43 QList<QSharedPointer<FileDBLink::DBInfo> > list; | |
| 44 foreach (QString key, entries.keys()) { | |
| 45 if (key.startsWith(prefix)) | |
| 46 list << entries[key]; | |
| 47 } | |
| 48 return list; | |
| 41 } | 49 } |
| 50 | |
| 51 | |
| 52 void MemoryDBLink::deleteFileFromDB(const QString& path) | |
| 53 { | |
| 54 entries.remove(path); | |
| 55 } | |
| 56 | |
| 57 | |
| 58 void MemoryDBLink::keepOnlyFromPrefix(const QString& prefix, const QStringList& files) | |
| 59 { | |
| 60 QStringList list; | |
| 61 foreach(QSharedPointer<DBInfo> info, values(prefix)) { | |
| 62 if (!files.contains(info->path())) { | |
| 63 list << info->path(); | |
| 64 } | |
| 65 } | |
| 66 foreach(QString path, list) { | |
| 67 deleteFileFromDB(path); | |
| 68 } | |
| 69 } | |
| 70 | |
| 71 FileDBLink::DBStatus MemoryDBLink::existsWithMtime(const QString& path, const QDateTime& mtime) | |
| 72 { | |
| 73 if (entries.contains(path)) { | |
| 74 QSharedPointer<DBInfo> info = entries[path]; | |
| 75 if (info->mtime() == mtime) | |
| 76 return SAME; | |
| 77 return MTIME_DIFFERENT; | |
| 78 } | |
| 79 return NONE; | |
| 80 } | |
| 81 | |
| 82 void MemoryDBLink::updateFile(const QString& path, qint64 size, const QDateTime& dtime, const QByteArray& hash) | |
| 83 { | |
| 84 updateFile(DBInfo(path, size, dtime, hash)); | |
| 85 } | |
| 86 | |
| 87 void MemoryDBLink::updateFile(const DBInfo& dbinfo) | |
| 88 { | |
| 89 *entries[dbinfo.path()] = dbinfo; | |
| 90 } | |
| 91 | |
| 92 |
