comparison OrthancServer/ServerIndex.cpp @ 2825:8aa6aef11b70

New configuration option "OverwriteInstances" to choose how duplicate SOPInstanceUID are handled
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Sep 2018 15:24:01 +0200
parents 46061a91c88a
children c277e0421200
comparison
equal deleted inserted replaced
2824:0e1b79bc4a2d 2825:8aa6aef11b70
624 624
625 try 625 try
626 { 626 {
627 Transaction t(*this); 627 Transaction t(*this);
628 628
629 // Do nothing if the instance already exists 629 // Check whether this instance is already stored
630 { 630 {
631 ResourceType type; 631 ResourceType type;
632 int64_t tmp; 632 int64_t tmp;
633 if (db_.LookupResource(tmp, type, hasher.HashInstance())) 633 if (db_.LookupResource(tmp, type, hasher.HashInstance()))
634 { 634 {
635 assert(type == ResourceType_Instance); 635 assert(type == ResourceType_Instance);
636 db_.GetAllMetadata(instanceMetadata, tmp); 636
637 return StoreStatus_AlreadyStored; 637 if (overwrite_)
638 {
639 // Overwrite the old instance
640 LOG(INFO) << "Overwriting instance: " << hasher.HashInstance();
641 db_.DeleteResource(tmp);
642 }
643 else
644 {
645 // Do nothing if the instance already exists
646 db_.GetAllMetadata(instanceMetadata, tmp);
647 return StoreStatus_AlreadyStored;
648 }
638 } 649 }
639 } 650 }
640 651
641 // Ensure there is enough room in the storage for the new instance 652 // Ensure there is enough room in the storage for the new instance
642 uint64_t instanceSize = 0; 653 uint64_t instanceSize = 0;
1459 } 1470 }
1460 1471
1461 StandaloneRecycling(); 1472 StandaloneRecycling();
1462 } 1473 }
1463 1474
1475 void ServerIndex::SetOverwriteInstances(bool overwrite)
1476 {
1477 boost::mutex::scoped_lock lock(mutex_);
1478 overwrite_ = overwrite;
1479 }
1480
1481
1464 void ServerIndex::StandaloneRecycling() 1482 void ServerIndex::StandaloneRecycling()
1465 { 1483 {
1466 // WARNING: No mutex here, do not include this as a public method 1484 // WARNING: No mutex here, do not include this as a public method
1467 Transaction t(*this); 1485 Transaction t(*this);
1468 Recycle(0, ""); 1486 Recycle(0, "");