comparison Plugin/Cache/CacheManager.cpp @ 197:0ef2d8b970ab

cppcheck
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 23 Apr 2018 11:42:31 +0200
parents 993dd140bd30
children 2f27287c047c
comparison
equal deleted inserted replaced
196:b83fe581f6ae 197:0ef2d8b970ab
226 std::list<std::string> toRemove; 226 std::list<std::string> toRemove;
227 MakeRoom(bundle, toRemove, bundleIndex, quota); 227 MakeRoom(bundle, toRemove, bundleIndex, quota);
228 228
229 transaction->Commit(); 229 transaction->Commit();
230 for (std::list<std::string>::const_iterator 230 for (std::list<std::string>::const_iterator
231 it = toRemove.begin(); it != toRemove.end(); it++) 231 it = toRemove.begin(); it != toRemove.end(); ++it)
232 { 232 {
233 pimpl_->storage_.Remove(*it, Orthanc::FileContentType_Unknown); 233 pimpl_->storage_.Remove(*it, Orthanc::FileContentType_Unknown);
234 } 234 }
235 235
236 pimpl_->bundles_[bundleIndex] = bundle; 236 pimpl_->bundles_[bundleIndex] = bundle;
355 // Store the cached content on the disk 355 // Store the cached content on the disk
356 const char* data = content.size() ? &content[0] : NULL; 356 const char* data = content.size() ? &content[0] : NULL;
357 std::string uuid = Toolbox::GenerateUuid(); 357 std::string uuid = Toolbox::GenerateUuid();
358 pimpl_->storage_.Create(uuid, data, content.size(), Orthanc::FileContentType_Unknown); 358 pimpl_->storage_.Create(uuid, data, content.size(), Orthanc::FileContentType_Unknown);
359 359
360 bool ok = true;
361
362 // Remove the previous cached value. This might happen if the same 360 // Remove the previous cached value. This might happen if the same
363 // item is accessed very quickly twice: Another factory could have 361 // item is accessed very quickly twice: Another factory could have
364 // been cached a value before the check for existence in Access(). 362 // been cached a value before the check for existence in Access().
365 { 363 {
366 SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE, "SELECT seq, fileUuid, fileSize FROM Cache WHERE bundle=? AND item=?"); 364 SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE, "SELECT seq, fileUuid, fileSize FROM Cache WHERE bundle=? AND item=?");
375 toRemove.push_back(s.ColumnString(1)); 373 toRemove.push_back(s.ColumnString(1));
376 bundle.Remove(s.ColumnInt64(2)); 374 bundle.Remove(s.ColumnInt64(2));
377 } 375 }
378 } 376 }
379 377
380 if (ok)
381 { 378 {
382 SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE, "INSERT INTO Cache VALUES(NULL, ?, ?, ?, ?)"); 379 SQLite::Statement s(pimpl_->db_, SQLITE_FROM_HERE, "INSERT INTO Cache VALUES(NULL, ?, ?, ?, ?)");
383 s.BindInt(0, bundleIndex); 380 s.BindInt(0, bundleIndex);
384 s.BindString(1, item); 381 s.BindString(1, item);
385 s.BindString(2, uuid); 382 s.BindString(2, uuid);
386 s.BindInt64(3, content.size()); 383 s.BindInt64(3, content.size());
387 384
388 if (!s.Run()) 385 if (!s.Run())
389 { 386 {
390 ok = false; 387 // Error: Remove the stored file
391 } 388 pimpl_->storage_.Remove(uuid, Orthanc::FileContentType_Unknown);
392 } 389 }
393 390 else
394 if (!ok) 391 {
395 { 392 transaction->Commit();
396 // Error: Remove the stored file 393
397 pimpl_->storage_.Remove(uuid, Orthanc::FileContentType_Unknown); 394 pimpl_->bundles_[bundleIndex] = bundle;
398 }
399 else
400 {
401 transaction->Commit();
402
403 pimpl_->bundles_[bundleIndex] = bundle;
404 395
405 for (std::list<std::string>::const_iterator 396 for (std::list<std::string>::const_iterator
406 it = toRemove.begin(); it != toRemove.end(); it++) 397 it = toRemove.begin(); it != toRemove.end(); ++it)
407 { 398 {
408 pimpl_->storage_.Remove(*it, Orthanc::FileContentType_Unknown); 399 pimpl_->storage_.Remove(*it, Orthanc::FileContentType_Unknown);
400 }
409 } 401 }
410 } 402 }
411 403
412 SanityCheck(); 404 SanityCheck();
413 } 405 }