comparison FileDBLink.cpp @ 2:2833b7f8884a

Sql backend is working. Need to get more speed on comparisson.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Tue, 21 Aug 2012 14:25:33 +0200
parents aae83c0a771d
children b5943e4bf676
comparison
equal deleted inserted replaced
1:aae83c0a771d 2:2833b7f8884a
15 #include <boost/bind.hpp> 15 #include <boost/bind.hpp>
16 16
17 void FileDBLink::updateIfModified(const QString& path) 17 void FileDBLink::updateIfModified(const QString& path)
18 { 18 {
19 QFileInfo fileinfo(path); 19 QFileInfo fileinfo(path);
20 if (!exists(path)) { 20 FileDBLink::DBStatus status = existsWithMtime(path, fileinfo.lastModified());
21
22 switch (status) {
23 case FileDBLink::NONE: {
21 addFile(fileinfo); 24 addFile(fileinfo);
25 break;
26 }
27 case FileDBLink::MTIME_DIFFERENT: {
28 updateFile(fileinfo);
29 }
30 default: {
31 }
22 } 32 }
23 } 33 }
24 34
25 void FileDBLink::addFile(const QFileInfo& fileinfo) 35 void FileDBLink::addFile(const QFileInfo& fileinfo)
26 { 36 {
43 default: 53 default:
44 throw IOException(errorMsg); 54 throw IOException(errorMsg);
45 } 55 }
46 } 56 }
47 57
48 addFile(path, size, lastModified, hash); 58 addFile(path, size, lastModified, hash.result());
49 59
50 } 60 }
51 61
52 const QList<QSharedPointer<FileDBLink::DBInfo> > FileDBLink::sortOn(SORTORDER order, bool extended) 62 void FileDBLink::updateFile(const QFileInfo& fileinfo)
53 { 63 {
54 QList<QSharedPointer<DBInfo> > list = (extended) ? computedValues() : computedValues(); 64 updateFile(fileinfo.absoluteFilePath(), fileinfo.size(), fileinfo.lastModified());
65 }
66
67 void FileDBLink::updateFile(const QString& path, qint64 size, const QDateTime& lastModified)
68 {
69 QCryptographicHash hash( QCryptographicHash::Sha1 );
70 QFile file(path);
71 if ( file.open( QIODevice::ReadOnly ) ) {
72 hash.addData( file.readAll() );
73 }
74 else {
75 QString errorMsg = path + ": " + file.errorString();
76 qDebug()<<file.error();
77 switch (file.error()) {
78 case QFile::PermissionsError:
79 throw PermissionException(errorMsg);
80 default:
81 throw IOException(errorMsg);
82 }
83 }
84
85 updateFile(path, size, lastModified, hash.result());
86 }
87
88 const QList<QSharedPointer<FileDBLink::DBInfo> > FileDBLink::sortOn(const QString& prefix, SORTORDER order, bool extended)
89 {
90 QList<QSharedPointer<DBInfo> > list = (extended) ? computedValues(prefix) : values(prefix);
55 91
56 switch (order) { 92 switch (order) {
57 case PATH: 93 case PATH:
58 { 94 {
59 QList<QSharedPointer<FileDBLink::DBInfo> > oList; 95 QList<QSharedPointer<FileDBLink::DBInfo> > oList;
120 } 156 }
121 } 157 }
122 return QSharedPointer<DBInfo>(new ExtendedDBInfo(*info, other, minDist)); 158 return QSharedPointer<DBInfo>(new ExtendedDBInfo(*info, other, minDist));
123 } 159 }
124 160
125 const QList<QSharedPointer<FileDBLink::DBInfo> > FileDBLink::computedValues() const 161 const QList<QSharedPointer<FileDBLink::DBInfo> > FileDBLink::computedValues(const QString& prefix) const
126 { 162 {
127 QList<QSharedPointer<DBInfo> > list; 163 QList<QSharedPointer<DBInfo> > list;
128 QList<QSharedPointer<DBInfo> > entries = values(); 164 QList<QSharedPointer<DBInfo> > entries = values(prefix);
129 165
130 #if 1 166 #if 1
131 list = QtConcurrent::blockingMapped(entries, boost::bind( &FileDBLink::computedValue, _1, entries)); 167 list = QtConcurrent::blockingMapped(entries, boost::bind( &FileDBLink::computedValue, _1, entries));
132 #else 168 #else
133 for (QList<QSharedPointer<DBInfo> >::const_iterator it1 = entries.begin(); 169 for (QList<QSharedPointer<DBInfo> >::const_iterator it1 = entries.begin();