# HG changeset patch # User Sebastien Jodogne # Date 1354882739 -3600 # Node ID 5b8e8b74bc8bf251561d2ac7707cd334fa7a28e5 # Parent 2354560daf2f42cfb600247856e12f958c327812 remove files only after the sqlite transaction has succeeded diff -r 2354560daf2f -r 5b8e8b74bc8b OrthancServer/ServerIndex.cpp --- a/OrthancServer/ServerIndex.cpp Fri Dec 07 12:56:27 2012 +0100 +++ b/OrthancServer/ServerIndex.cpp Fri Dec 07 13:18:59 2012 +0100 @@ -59,6 +59,7 @@ bool hasRemainingLevel_; ResourceType remainingType_; std::string remainingPublicId_; + std::list pendingFilesToRemove_; public: ServerIndexListener(ServerContext& context) : @@ -73,6 +74,17 @@ void Reset() { hasRemainingLevel_ = false; + pendingFilesToRemove_.clear(); + } + + void CommitFilesToRemove() + { + for (std::list::iterator + it = pendingFilesToRemove_.begin(); + it != pendingFilesToRemove_.end(); it++) + { + context_.RemoveFile(*it); + } } virtual void SignalRemainingAncestor(ResourceType parentType, @@ -99,7 +111,7 @@ virtual void SignalFileDeleted(const std::string& fileUuid) { assert(Toolbox::IsUuid(fileUuid)); - context_.RemoveFile(fileUuid); + pendingFilesToRemove_.push_back(fileUuid); } bool HasRemainingLevel() const @@ -160,6 +172,10 @@ t->Commit(); + // We can remove the files once the SQLite transaction has been + // successfully committed + listener_->CommitFilesToRemove(); + return true; }