access/qnetworkdiskcache.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3QNetworkDiskCache::QNetworkDiskCache(QObject *parent) -
4 : QAbstractNetworkCache(*new QNetworkDiskCachePrivate, parent) -
5{ -
6}
executed: }
Execution Count:61
61
7 -
8 -
9 -
10 -
11QNetworkDiskCache::~QNetworkDiskCache() -
12{ -
13 QNetworkDiskCachePrivate * const d = d_func(); -
14 QHashIterator<QIODevice*, QCacheItem*> it(d->inserting); -
15 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:61
2-61
16 it.next(); -
17 delete it.value(); -
18 }
executed: }
Execution Count:2
2
19}
executed: }
Execution Count:61
61
20 -
21 -
22 -
23 -
24QString QNetworkDiskCache::cacheDirectory() const -
25{ -
26 const QNetworkDiskCachePrivate * const d = d_func(); -
27 return d->cacheDirectory;
executed: return d->cacheDirectory;
Execution Count:200
200
28} -
29void QNetworkDiskCache::setCacheDirectory(const QString &cacheDir) -
30{ -
31 -
32 -
33 -
34 QNetworkDiskCachePrivate * const d = d_func(); -
35 if (cacheDir.isEmpty())
evaluated: cacheDir.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:60
2-60
36 return;
executed: return;
Execution Count:2
2
37 d->cacheDirectory = cacheDir; -
38 QDir dir(d->cacheDirectory); -
39 d->cacheDirectory = dir.absolutePath(); -
40 if (!d->cacheDirectory.endsWith(QLatin1Char('/')))
partially evaluated: !d->cacheDirectory.endsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:60
no
Evaluation Count:0
0-60
41 d->cacheDirectory += QLatin1Char('/');
executed: d->cacheDirectory += QLatin1Char('/');
Execution Count:60
60
42 -
43 d->dataDirectory = d->cacheDirectory + QLatin1String("data") + QString::number(7) + QLatin1Char('/'); -
44 d->prepareLayout(); -
45}
executed: }
Execution Count:60
60
46 -
47 -
48 -
49 -
50qint64 QNetworkDiskCache::cacheSize() const -
51{ -
52 -
53 -
54 -
55 const QNetworkDiskCachePrivate * const d = d_func(); -
56 if (d->cacheDirectory.isEmpty())
evaluated: d->cacheDirectory.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4
1-4
57 return 0;
executed: return 0;
Execution Count:1
1
58 if (d->currentCacheSize < 0) {
evaluated: d->currentCacheSize < 0
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
59 QNetworkDiskCache *that = const_cast<QNetworkDiskCache*>(this); -
60 that->d_func()->currentCacheSize = that->expire(); -
61 }
executed: }
Execution Count:1
1
62 return d->currentCacheSize;
executed: return d->currentCacheSize;
Execution Count:4
4
63} -
64 -
65 -
66 -
67 -
68QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) -
69{ -
70 -
71 -
72 -
73 QNetworkDiskCachePrivate * const d = d_func(); -
74 if (!metaData.isValid() || !metaData.url().isValid() || !metaData.saveToDisk())
evaluated: !metaData.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:94
partially evaluated: !metaData.url().isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:94
evaluated: !metaData.saveToDisk()
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:87
0-94
75 return 0;
executed: return 0;
Execution Count:8
8
76 -
77 if (d->cacheDirectory.isEmpty()) {
evaluated: d->cacheDirectory.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:86
1-86
78 QMessageLogger("access/qnetworkdiskcache.cpp", 194, __PRETTY_FUNCTION__).warning() << "QNetworkDiskCache::prepare() The cache directory is not set"; -
79 return 0;
executed: return 0;
Execution Count:1
1
80 } -
81 -
82 for (QForeachContainer<__typeof__(metaData.rawHeaders())> _container_(metaData.rawHeaders()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkCacheMetaData::RawHeader &header = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
83 if (header.first.toLower() == "content-length") {
evaluated: header.first.toLower() == "content-length"
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:248
12-248
84 const qint64 size = header.second.toLongLong(); -
85 if (size > (maximumCacheSize() * 3)/4)
partially evaluated: size > (maximumCacheSize() * 3)/4
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12
0-12
86 return 0;
never executed: return 0;
0
87 break;
executed: break;
Execution Count:12
12
88 } -
89 }
executed: }
Execution Count:248
248
90 QScopedPointer<QCacheItem> cacheItem(new QCacheItem); -
91 cacheItem->metaData = metaData; -
92 -
93 QIODevice *device = 0; -
94 if (cacheItem->canCompress()) {
evaluated: cacheItem->canCompress()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:74
12-74
95 cacheItem->data.open(QBuffer::ReadWrite); -
96 device = &(cacheItem->data); -
97 } else {
executed: }
Execution Count:12
12
98 QString templateName = d->tmpCacheFileName(); -
99 if (true) {
partially evaluated: true
TRUEFALSE
yes
Evaluation Count:74
no
Evaluation Count:0
0-74
100 cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data); -
101 } else {
executed: }
Execution Count:74
74
102 cacheItem->file = 0; -
103 }
never executed: }
0
104 if (!cacheItem->file || !cacheItem->file->open()) {
partially evaluated: !cacheItem->file
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:74
partially evaluated: !cacheItem->file->open()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:74
0-74
105 QMessageLogger("access/qnetworkdiskcache.cpp", 221, __PRETTY_FUNCTION__).warning() << "QNetworkDiskCache::prepare() unable to open temporary file"; -
106 cacheItem.reset(); -
107 return 0;
never executed: return 0;
0
108 } -
109 cacheItem->writeHeader(cacheItem->file); -
110 device = cacheItem->file; -
111 }
executed: }
Execution Count:74
74
112 d->inserting[device] = cacheItem.take(); -
113 return device;
executed: return device;
Execution Count:86
86
114} -
115 -
116 -
117 -
118 -
119void QNetworkDiskCache::insert(QIODevice *device) -
120{ -
121 -
122 -
123 -
124 QNetworkDiskCachePrivate * const d = d_func(); -
125 QHash<QIODevice*, QCacheItem*>::iterator it = d->inserting.find(device); -
126 if (it == d->inserting.end()) {
evaluated: it == d->inserting.end()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:84
1-84
127 QMessageLogger("access/qnetworkdiskcache.cpp", 243, __PRETTY_FUNCTION__).warning() << "QNetworkDiskCache::insert() called on a device we don't know about" << device; -
128 return;
executed: return;
Execution Count:1
1
129 } -
130 -
131 d->storeItem(it.value()); -
132 delete it.value(); -
133 d->inserting.erase(it); -
134}
executed: }
Execution Count:84
84
135 -
136 -
137 -
138 -
139 -
140 -
141void QNetworkDiskCachePrivate::prepareLayout() -
142{ -
143 QDir helper; -
144 helper.mkpath(cacheDirectory + QLatin1String("prepared/")); -
145 -
146 -
147 helper.mkpath(dataDirectory); -
148 for (uint i = 0; i < 16 ; i++) {
evaluated: i < 16
TRUEFALSE
yes
Evaluation Count:960
yes
Evaluation Count:60
60-960
149 QString str = QString::number(i, 16); -
150 QString subdir = dataDirectory + str; -
151 helper.mkdir(subdir); -
152 }
executed: }
Execution Count:960
960
153}
executed: }
Execution Count:60
60
154 -
155 -
156void QNetworkDiskCachePrivate::storeItem(QCacheItem *cacheItem) -
157{ -
158 QNetworkDiskCache * const q = q_func(); -
159 qt_noop(); -
160 -
161 QString fileName = cacheFileName(cacheItem->metaData.url()); -
162 qt_noop(); -
163 -
164 if (QFile::exists(fileName)) {
evaluated: QFile::exists(fileName)
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:61
23-61
165 if (!QFile::remove(fileName)) {
partially evaluated: !QFile::remove(fileName)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23
0-23
166 QMessageLogger("access/qnetworkdiskcache.cpp", 282, __PRETTY_FUNCTION__).warning() << "QNetworkDiskCache: couldn't remove the cache file " << fileName; -
167 return;
never executed: return;
0
168 } -
169 }
executed: }
Execution Count:23
23
170 -
171 if (currentCacheSize > 0)
evaluated: currentCacheSize > 0
TRUEFALSE
yes
Evaluation Count:33
yes
Evaluation Count:51
33-51
172 currentCacheSize += 1024 + cacheItem->size();
executed: currentCacheSize += 1024 + cacheItem->size();
Execution Count:33
33
173 currentCacheSize = q->expire(); -
174 if (!cacheItem->file) {
evaluated: !cacheItem->file
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:72
12-72
175 QString templateName = tmpCacheFileName(); -
176 cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data); -
177 if (cacheItem->file->open()) {
partially evaluated: cacheItem->file->open()
TRUEFALSE
yes
Evaluation Count:12
no
Evaluation Count:0
0-12
178 cacheItem->writeHeader(cacheItem->file); -
179 cacheItem->writeCompressedData(cacheItem->file); -
180 }
executed: }
Execution Count:12
12
181 }
executed: }
Execution Count:12
12
182 -
183 if (cacheItem->file
partially evaluated: cacheItem->file
TRUEFALSE
yes
Evaluation Count:84
no
Evaluation Count:0
0-84
184 && cacheItem->file->isOpen()
partially evaluated: cacheItem->file->isOpen()
TRUEFALSE
yes
Evaluation Count:84
no
Evaluation Count:0
0-84
185 && cacheItem->file->error() == QFile::NoError) {
partially evaluated: cacheItem->file->error() == QFile::NoError
TRUEFALSE
yes
Evaluation Count:84
no
Evaluation Count:0
0-84
186 cacheItem->file->setAutoRemove(false); -
187 -
188 if (cacheItem->file->rename(fileName))
partially evaluated: cacheItem->file->rename(fileName)
TRUEFALSE
yes
Evaluation Count:84
no
Evaluation Count:0
0-84
189 currentCacheSize += cacheItem->file->size();
executed: currentCacheSize += cacheItem->file->size();
Execution Count:84
84
190 else -
191 cacheItem->file->setAutoRemove(true);
never executed: cacheItem->file->setAutoRemove(true);
0
192 } -
193 if (cacheItem->metaData.url() == lastItem.metaData.url())
evaluated: cacheItem->metaData.url() == lastItem.metaData.url()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:69
15-69
194 lastItem.reset();
executed: lastItem.reset();
Execution Count:15
15
195}
executed: }
Execution Count:84
84
196 -
197 -
198 -
199 -
200bool QNetworkDiskCache::remove(const QUrl &url) -
201{ -
202 -
203 -
204 -
205 QNetworkDiskCachePrivate * const d = d_func(); -
206 -
207 -
208 QHashIterator<QIODevice*, QCacheItem*> it(d->inserting); -
209 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:14
1-14
210 it.next(); -
211 QCacheItem *item = it.value(); -
212 if (item && item->metaData.url() == url) {
partially evaluated: item
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
partially evaluated: item->metaData.url() == url
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
213 delete item; -
214 d->inserting.remove(it.key()); -
215 return true;
never executed: return true;
0
216 } -
217 }
executed: }
Execution Count:1
1
218 -
219 if (d->lastItem.metaData.url() == url)
evaluated: d->lastItem.metaData.url() == url
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:11
3-11
220 d->lastItem.reset();
executed: d->lastItem.reset();
Execution Count:3
3
221 return d->removeFile(d->cacheFileName(url));
executed: return d->removeFile(d->cacheFileName(url));
Execution Count:14
14
222} -
223 -
224 -
225 -
226 -
227bool QNetworkDiskCachePrivate::removeFile(const QString &file) -
228{ -
229 -
230 -
231 -
232 if (file.isEmpty())
evaluated: file.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:14
1-14
233 return false;
executed: return false;
Execution Count:1
1
234 QFileInfo info(file); -
235 QString fileName = info.fileName(); -
236 if (!fileName.endsWith(QLatin1String(".d")))
partially evaluated: !fileName.endsWith(QLatin1String(".d"))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:14
0-14
237 return false;
never executed: return false;
0
238 qint64 size = info.size(); -
239 if (QFile::remove(file)) {
evaluated: QFile::remove(file)
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:9
5-9
240 currentCacheSize -= size; -
241 return true;
executed: return true;
Execution Count:5
5
242 } -
243 return false;
executed: return false;
Execution Count:9
9
244} -
245 -
246 -
247 -
248 -
249QNetworkCacheMetaData QNetworkDiskCache::metaData(const QUrl &url) -
250{ -
251 -
252 -
253 -
254 QNetworkDiskCachePrivate * const d = d_func(); -
255 if (d->lastItem.metaData.url() == url)
evaluated: d->lastItem.metaData.url() == url
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:86
8-86
256 return d->lastItem.metaData;
executed: return d->lastItem.metaData;
Execution Count:8
8
257 return fileMetaData(d->cacheFileName(url));
executed: return fileMetaData(d->cacheFileName(url));
Execution Count:86
86
258} -
259 -
260 -
261 -
262 -
263 -
264 -
265QNetworkCacheMetaData QNetworkDiskCache::fileMetaData(const QString &fileName) const -
266{ -
267 -
268 -
269 -
270 const QNetworkDiskCachePrivate * const d = d_func(); -
271 QFile file(fileName); -
272 if (!file.open(QFile::ReadOnly))
evaluated: !file.open(QFile::ReadOnly)
TRUEFALSE
yes
Evaluation Count:50
yes
Evaluation Count:44
44-50
273 return QNetworkCacheMetaData();
executed: return QNetworkCacheMetaData();
Execution Count:50
50
274 if (!d->lastItem.read(&file, false)) {
evaluated: !d->lastItem.read(&file, false)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:43
1-43
275 file.close(); -
276 QNetworkDiskCachePrivate *that = const_cast<QNetworkDiskCachePrivate*>(d); -
277 that->removeFile(fileName); -
278 }
executed: }
Execution Count:1
1
279 return d->lastItem.metaData;
executed: return d->lastItem.metaData;
Execution Count:44
44
280} -
281 -
282 -
283 -
284 -
285QIODevice *QNetworkDiskCache::data(const QUrl &url) -
286{ -
287 -
288 -
289 -
290 QNetworkDiskCachePrivate * const d = d_func(); -
291 QScopedPointer<QBuffer> buffer; -
292 if (!url.isValid())
evaluated: !url.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:39
1-39
293 return 0;
executed: return 0;
Execution Count:1
1
294 if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) {
evaluated: d->lastItem.metaData.url() == url
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:14
partially evaluated: d->lastItem.data.isOpen()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:25
0-25
295 buffer.reset(new QBuffer); -
296 buffer->setData(d->lastItem.data.data()); -
297 } else {
never executed: }
0
298 QScopedPointer<QFile> file(new QFile(d->cacheFileName(url))); -
299 if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered))
partially evaluated: !file->open(QFile::ReadOnly | QIODevice::Unbuffered)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:39
0-39
300 return 0;
never executed: return 0;
0
301 -
302 if (!d->lastItem.read(file.data(), true)) {
evaluated: !d->lastItem.read(file.data(), true)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:38
1-38
303 file->close(); -
304 remove(url); -
305 return 0;
executed: return 0;
Execution Count:1
1
306 } -
307 if (d->lastItem.data.isOpen()) {
evaluated: d->lastItem.data.isOpen()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:29
9-29
308 -
309 buffer.reset(new QBuffer); -
310 buffer->setData(d->lastItem.data.data()); -
311 } else {
executed: }
Execution Count:9
9
312 buffer.reset(new QBuffer); -
313 -
314 qint64 size = file->size() - file->pos(); -
315 const uchar *p = 0; -
316 -
317 p = file->map(file->pos(), size); -
318 -
319 if (p) {
partially evaluated: p
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-29
320 buffer->setData((const char *)p, size); -
321 file.take()->setParent(buffer.data()); -
322 } else {
executed: }
Execution Count:29
29
323 buffer->setData(file->readAll()); -
324 }
never executed: }
0
325 } -
326 } -
327 buffer->open(QBuffer::ReadOnly); -
328 return buffer.take();
executed: return buffer.take();
Execution Count:38
38
329} -
330 -
331 -
332 -
333 -
334void QNetworkDiskCache::updateMetaData(const QNetworkCacheMetaData &metaData) -
335{ -
336 -
337 -
338 -
339 QUrl url = metaData.url(); -
340 QIODevice *oldDevice = data(url); -
341 if (!oldDevice) {
evaluated: !oldDevice
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:8
1-8
342 -
343 -
344 -
345 return;
executed: return;
Execution Count:1
1
346 } -
347 -
348 QIODevice *newDevice = prepare(metaData); -
349 if (!newDevice) {
partially evaluated: !newDevice
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
350 -
351 -
352 -
353 return;
never executed: return;
0
354 } -
355 char data[1024]; -
356 while (!oldDevice->atEnd()) {
evaluated: !oldDevice->atEnd()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:8
8
357 qint64 s = oldDevice->read(data, 1024); -
358 newDevice->write(data, s); -
359 }
executed: }
Execution Count:8
8
360 delete oldDevice; -
361 insert(newDevice); -
362}
executed: }
Execution Count:8
8
363 -
364 -
365 -
366 -
367 -
368 -
369qint64 QNetworkDiskCache::maximumCacheSize() const -
370{ -
371 const QNetworkDiskCachePrivate * const d = d_func(); -
372 return d->maximumCacheSize;
executed: return d->maximumCacheSize;
Execution Count:199
199
373} -
374void QNetworkDiskCache::setMaximumCacheSize(qint64 size) -
375{ -
376 QNetworkDiskCachePrivate * const d = d_func(); -
377 bool expireCache = (size < d->maximumCacheSize); -
378 d->maximumCacheSize = size; -
379 if (expireCache)
partially evaluated: expireCache
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
380 d->currentCacheSize = expire();
executed: d->currentCacheSize = expire();
Execution Count:1
1
381}
executed: }
Execution Count:1
1
382qint64 QNetworkDiskCache::expire() -
383{ -
384 QNetworkDiskCachePrivate * const d = d_func(); -
385 if (d->currentCacheSize >= 0 && d->currentCacheSize < maximumCacheSize())
evaluated: d->currentCacheSize >= 0
TRUEFALSE
yes
Evaluation Count:99
yes
Evaluation Count:59
evaluated: d->currentCacheSize < maximumCacheSize()
TRUEFALSE
yes
Evaluation Count:70
yes
Evaluation Count:29
29-99
386 return d->currentCacheSize;
executed: return d->currentCacheSize;
Execution Count:70
70
387 -
388 if (cacheDirectory().isEmpty()) {
evaluated: cacheDirectory().isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:87
1-87
389 QMessageLogger("access/qnetworkdiskcache.cpp", 532, __PRETTY_FUNCTION__).warning() << "QNetworkDiskCache::expire() The cache directory is not set"; -
390 return 0;
executed: return 0;
Execution Count:1
1
391 } -
392 -
393 -
394 d->lastItem.reset(); -
395 -
396 QDir::Filters filters = QDir::AllDirs | QDir:: Files | QDir::NoDotAndDotDot; -
397 QDirIterator it(cacheDirectory(), filters, QDirIterator::Subdirectories); -
398 -
399 QMultiMap<QDateTime, QString> cacheItems; -
400 qint64 totalSize = 0; -
401 while (it.hasNext()) {
evaluated: it.hasNext()
TRUEFALSE
yes
Evaluation Count:1660
yes
Evaluation Count:87
87-1660
402 QString path = it.next(); -
403 QFileInfo info = it.fileInfo(); -
404 QString fileName = info.fileName(); -
405 if (fileName.endsWith(QLatin1String(".d"))) {
evaluated: fileName.endsWith(QLatin1String(".d"))
TRUEFALSE
yes
Evaluation Count:93
yes
Evaluation Count:1567
93-1567
406 cacheItems.insert(info.created(), path); -
407 totalSize += info.size(); -
408 }
executed: }
Execution Count:93
93
409 }
executed: }
Execution Count:1660
1660
410 -
411 int removedFiles = 0; -
412 qint64 goal = (maximumCacheSize() * 9) / 10; -
413 QMultiMap<QDateTime, QString>::const_iterator i = cacheItems.constBegin(); -
414 while (i != cacheItems.constEnd()) {
evaluated: i != cacheItems.constEnd()
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:61
46-61
415 if (totalSize < goal)
evaluated: totalSize < goal
TRUEFALSE
yes
Evaluation Count:26
yes
Evaluation Count:20
20-26
416 break;
executed: break;
Execution Count:26
26
417 QString name = i.value(); -
418 QFile file(name); -
419 qint64 size = file.size(); -
420 file.remove(); -
421 totalSize -= size; -
422 ++removedFiles; -
423 ++i; -
424 }
executed: }
Execution Count:20
20
425 -
426 -
427 -
428 -
429 -
430 -
431 -
432 return totalSize;
executed: return totalSize;
Execution Count:87
87
433} -
434 -
435 -
436 -
437 -
438void QNetworkDiskCache::clear() -
439{ -
440 -
441 -
442 -
443 QNetworkDiskCachePrivate * const d = d_func(); -
444 qint64 size = d->maximumCacheSize; -
445 d->maximumCacheSize = 0; -
446 d->currentCacheSize = expire(); -
447 d->maximumCacheSize = size; -
448}
executed: }
Execution Count:60
60
449 -
450 -
451 -
452 -
453QString QNetworkDiskCachePrivate::uniqueFileName(const QUrl &url) -
454{ -
455 QUrl cleanUrl = url; -
456 cleanUrl.setPassword(QString()); -
457 cleanUrl.setFragment(QString()); -
458 -
459 QCryptographicHash hash(QCryptographicHash::Sha1); -
460 hash.addData(cleanUrl.toEncoded()); -
461 -
462 QByteArray id = QByteArray::number(*(qlonglong*)hash.result().data(), 36).left(8); -
463 -
464 uint code = (uint)id.at(id.length()-1) % 16; -
465 QString pathFragment = QString::number(code, 16) + QLatin1Char('/') -
466 + QLatin1String(id) + QLatin1String(".d"); -
467 -
468 return pathFragment;
executed: return pathFragment;
Execution Count:302
302
469} -
470 -
471QString QNetworkDiskCachePrivate::tmpCacheFileName() const -
472{ -
473 -
474 return cacheDirectory + QLatin1String("prepared/") + QLatin1String("XXXXXX") + QLatin1String(".d");
executed: return cacheDirectory + QLatin1String("prepared/") + QLatin1String("XXXXXX") + QLatin1String(".d");
Execution Count:86
86
475} -
476 -
477 -
478 -
479 -
480QString QNetworkDiskCachePrivate::cacheFileName(const QUrl &url) const -
481{ -
482 if (!url.isValid())
evaluated: !url.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:222
1-222
483 return QString();
executed: return QString();
Execution Count:1
1
484 -
485 QString fullpath = dataDirectory + uniqueFileName(url); -
486 return fullpath;
executed: return fullpath;
Execution Count:222
222
487} -
488 -
489 -
490 -
491 -
492bool QCacheItem::canCompress() const -
493{ -
494 bool sizeOk = false; -
495 bool typeOk = false; -
496 for (QForeachContainer<__typeof__(metaData.rawHeaders())> _container_(metaData.rawHeaders()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkCacheMetaData::RawHeader &header = *_container_.i;; __extension__ ({--_container_.brk; break;})) { -
497 if (header.first.toLower() == "content-length") {
evaluated: header.first.toLower() == "content-length"
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:520
24-520
498 qint64 size = header.second.toLongLong(); -
499 if (size > (1024 * 1024 * 3))
partially evaluated: size > (1024 * 1024 * 3)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24
0-24
500 return false;
never executed: return false;
0
501 else -
502 sizeOk = true;
executed: sizeOk = true;
Execution Count:24
24
503 } -
504 -
505 if (header.first.toLower() == "content-type") {
evaluated: header.first.toLower() == "content-type"
TRUEFALSE
yes
Evaluation Count:142
yes
Evaluation Count:402
142-402
506 QByteArray type = header.second; -
507 if (type.startsWith("text/")
partially evaluated: type.startsWith("text/")
TRUEFALSE
yes
Evaluation Count:142
no
Evaluation Count:0
0-142
508 || (type.startsWith("application/")
never evaluated: type.startsWith("application/")
0
509 && (type.endsWith("javascript") || type.endsWith("ecmascript"))))
never evaluated: type.endsWith("javascript")
never evaluated: type.endsWith("ecmascript")
0
510 typeOk = true;
executed: typeOk = true;
Execution Count:142
142
511 else -
512 return false;
never executed: return false;
0
513 } -
514 if (sizeOk && typeOk)
evaluated: sizeOk
TRUEFALSE
yes
Evaluation Count:48
yes
Evaluation Count:496
evaluated: typeOk
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:24
24-496
515 return true;
executed: return true;
Execution Count:24
24
516 }
executed: }
Execution Count:520
520
517 return false;
executed: return false;
Execution Count:148
148
518} -
519 -
520enum -
521{ -
522 CacheMagic = 0xe8, -
523 CurrentCacheVersion = 7 -
524}; -
525 -
526void QCacheItem::writeHeader(QFile *device) const -
527{ -
528 QDataStream out(device); -
529 -
530 out << qint32(CacheMagic); -
531 out << qint32(CurrentCacheVersion); -
532 out << metaData; -
533 bool compressed = canCompress(); -
534 out << compressed; -
535}
executed: }
Execution Count:86
86
536 -
537void QCacheItem::writeCompressedData(QFile *device) const -
538{ -
539 QDataStream out(device); -
540 -
541 out << qCompress(data.data()); -
542}
executed: }
Execution Count:12
12
543 -
544 -
545 -
546 -
547 -
548bool QCacheItem::read(QFile *device, bool readData) -
549{ -
550 reset(); -
551 -
552 QDataStream in(device); -
553 -
554 qint32 marker; -
555 qint32 v; -
556 in >> marker; -
557 in >> v; -
558 if (marker != CacheMagic)
evaluated: marker != CacheMagic
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:82
1-82
559 return true;
executed: return true;
Execution Count:1
1
560 -
561 -
562 if (v != CurrentCacheVersion)
evaluated: v != CurrentCacheVersion
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:80
2-80
563 return false;
executed: return false;
Execution Count:2
2
564 -
565 bool compressed; -
566 QByteArray dataBA; -
567 in >> metaData; -
568 in >> compressed; -
569 if (readData && compressed) {
evaluated: readData
TRUEFALSE
yes
Evaluation Count:38
yes
Evaluation Count:42
evaluated: compressed
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:29
9-42
570 in >> dataBA; -
571 data.setData(qUncompress(dataBA)); -
572 data.open(QBuffer::ReadOnly); -
573 }
executed: }
Execution Count:9
9
574 -
575 -
576 QString expectedFilename = QNetworkDiskCachePrivate::uniqueFileName(metaData.url()); -
577 if (!device->fileName().endsWith(expectedFilename))
partially evaluated: !device->fileName().endsWith(expectedFilename)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:80
0-80
578 return false;
never executed: return false;
0
579 -
580 return metaData.isValid();
executed: return metaData.isValid();
Execution Count:80
80
581} -
582 -
583 -
584 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial