Mercurial > dedupe
comparison MemoryDBLink.cpp @ 64:b9515dc35fe4
Make sure no file has greater linewidth than 80.
| author | Tom Fredrik Blenning Klaussen <bfg@blenning.no> |
|---|---|
| date | Fri, 14 Sep 2012 22:50:45 +0200 |
| parents | d6fdca3bf24e |
| children | c9447697609f |
comparison
equal
deleted
inserted
replaced
| 63:dd086ec3220d | 64:b9515dc35fe4 |
|---|---|
| 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 QByteArray& hash) | 5 void MemoryDBLink::addFile(const QString& path, qint64 size, |
| 6 const QDateTime& dtime, const QByteArray& hash) | |
| 6 { | 7 { |
| 7 addFile(DBInfo(path, size, dtime, hash)); | 8 addFile(DBInfo(path, size, dtime, hash)); |
| 8 } | 9 } |
| 9 | 10 |
| 10 bool MemoryDBLink::tryAddFile(const DBInfo& dbinfo) | 11 bool MemoryDBLink::tryAddFile(const DBInfo& dbinfo) |
| 11 { | 12 { |
| 12 QMap<QString, QSharedPointer<DBInfo> >::iterator pos; | 13 QMap<QString, dbinf_ptr_t >::iterator pos; |
| 13 pos = entries.find(dbinfo.path()); | 14 pos = entries.find(dbinfo.path()); |
| 14 if (pos == entries.end()) { | 15 if (pos == entries.end()) { |
| 15 entries.insert(dbinfo.path(), QSharedPointer<DBInfo>(new DBInfo(dbinfo))); | 16 entries.insert(dbinfo.path(), dbinf_ptr_t(new DBInfo(dbinfo))); |
| 16 return true; | 17 return true; |
| 17 } | 18 } |
| 18 return false; | 19 return false; |
| 19 } | 20 } |
| 20 | 21 |
| 27 | 28 |
| 28 | 29 |
| 29 QStringList MemoryDBLink::toStringList() | 30 QStringList MemoryDBLink::toStringList() |
| 30 { | 31 { |
| 31 QStringList list; | 32 QStringList list; |
| 32 foreach(QSharedPointer<DBInfo> info, entries) { | 33 foreach(dbinf_ptr_t info, entries) { |
| 33 list << info->serialize(); | 34 list << info->serialize(); |
| 34 } | 35 } |
| 35 return list; | 36 return list; |
| 36 } | 37 } |
| 37 | 38 |
| 38 const QList<QSharedPointer<FileDBLink::DBInfo> > MemoryDBLink::values(const QString& prefix) const | 39 const QList<FileDBLink::dbinf_ptr_t> |
| 40 MemoryDBLink::values(const QString& prefix) const | |
| 39 { | 41 { |
| 40 if (prefix.size() == 0) | 42 if (prefix.size() == 0) |
| 41 return entries.values(); | 43 return entries.values(); |
| 42 | 44 |
| 43 QList<QSharedPointer<FileDBLink::DBInfo> > list; | 45 QList<FileDBLink::dbinf_ptr_t > list; |
| 44 foreach (QString key, entries.keys()) { | 46 foreach (QString key, entries.keys()) { |
| 45 if (key.startsWith(prefix)) | 47 if (key.startsWith(prefix)) |
| 46 list << entries[key]; | 48 list << entries[key]; |
| 47 } | 49 } |
| 48 return list; | 50 return list; |
| 53 { | 55 { |
| 54 entries.remove(path); | 56 entries.remove(path); |
| 55 } | 57 } |
| 56 | 58 |
| 57 | 59 |
| 58 void MemoryDBLink::keepOnlyFromPrefix(const QString& prefix, const QStringList& files) | 60 void MemoryDBLink::keepOnlyFromPrefix(const QString& prefix, |
| 61 const QStringList& files) | |
| 59 { | 62 { |
| 60 QStringList list; | 63 QStringList list; |
| 61 foreach(QSharedPointer<DBInfo> info, values(prefix)) { | 64 foreach(dbinf_ptr_t info, values(prefix)) { |
| 62 if (!files.contains(info->path())) { | 65 if (!files.contains(info->path())) { |
| 63 list << info->path(); | 66 list << info->path(); |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 foreach(QString path, list) { | 69 foreach(QString path, list) { |
| 67 deleteFileFromDB(path); | 70 deleteFileFromDB(path); |
| 68 } | 71 } |
| 69 } | 72 } |
| 70 | 73 |
| 71 FileDBLink::DBStatus MemoryDBLink::existsWithMtime(const QString& path, const QDateTime& mtime) | 74 FileDBLink::DBStatus MemoryDBLink::existsWithMtime(const QString& path, |
| 75 const QDateTime& mtime) | |
| 72 { | 76 { |
| 73 if (entries.contains(path)) { | 77 if (entries.contains(path)) { |
| 74 QSharedPointer<DBInfo> info = entries[path]; | 78 dbinf_ptr_t info = entries[path]; |
| 75 if (info->mtime() == mtime) | 79 if (info->mtime() == mtime) |
| 76 return SAME; | 80 return SAME; |
| 77 return MTIME_DIFFERENT; | 81 return MTIME_DIFFERENT; |
| 78 } | 82 } |
| 79 return NONE; | 83 return NONE; |
| 80 } | 84 } |
| 81 | 85 |
| 82 void MemoryDBLink::updateFile(const QString& path, qint64 size, const QDateTime& dtime, const QByteArray& hash) | 86 void MemoryDBLink::updateFile(const QString& path, qint64 size, |
| 87 const QDateTime& dtime, const QByteArray& hash) | |
| 83 { | 88 { |
| 84 updateFile(DBInfo(path, size, dtime, hash)); | 89 updateFile(DBInfo(path, size, dtime, hash)); |
| 85 } | 90 } |
| 86 | 91 |
| 87 void MemoryDBLink::updateFile(const DBInfo& dbinfo) | 92 void MemoryDBLink::updateFile(const DBInfo& dbinfo) |
