comparison OrthancServer/ServerIndex.cpp @ 264:5b8e8b74bc8b

remove files only after the sqlite transaction has succeeded
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Dec 2012 13:18:59 +0100
parents 2766fac53c81
children 4bc02e2254ec
comparison
equal deleted inserted replaced
262:2354560daf2f 264:5b8e8b74bc8b
57 private: 57 private:
58 ServerContext& context_; 58 ServerContext& context_;
59 bool hasRemainingLevel_; 59 bool hasRemainingLevel_;
60 ResourceType remainingType_; 60 ResourceType remainingType_;
61 std::string remainingPublicId_; 61 std::string remainingPublicId_;
62 std::list<std::string> pendingFilesToRemove_;
62 63
63 public: 64 public:
64 ServerIndexListener(ServerContext& context) : 65 ServerIndexListener(ServerContext& context) :
65 context_(context), 66 context_(context),
66 hasRemainingLevel_(false) 67 hasRemainingLevel_(false)
71 } 72 }
72 73
73 void Reset() 74 void Reset()
74 { 75 {
75 hasRemainingLevel_ = false; 76 hasRemainingLevel_ = false;
77 pendingFilesToRemove_.clear();
78 }
79
80 void CommitFilesToRemove()
81 {
82 for (std::list<std::string>::iterator
83 it = pendingFilesToRemove_.begin();
84 it != pendingFilesToRemove_.end(); it++)
85 {
86 context_.RemoveFile(*it);
87 }
76 } 88 }
77 89
78 virtual void SignalRemainingAncestor(ResourceType parentType, 90 virtual void SignalRemainingAncestor(ResourceType parentType,
79 const std::string& publicId) 91 const std::string& publicId)
80 { 92 {
97 } 109 }
98 110
99 virtual void SignalFileDeleted(const std::string& fileUuid) 111 virtual void SignalFileDeleted(const std::string& fileUuid)
100 { 112 {
101 assert(Toolbox::IsUuid(fileUuid)); 113 assert(Toolbox::IsUuid(fileUuid));
102 context_.RemoveFile(fileUuid); 114 pendingFilesToRemove_.push_back(fileUuid);
103 } 115 }
104 116
105 bool HasRemainingLevel() const 117 bool HasRemainingLevel() const
106 { 118 {
107 return hasRemainingLevel_; 119 return hasRemainingLevel_;
157 { 169 {
158 target["RemainingAncestor"] = Json::nullValue; 170 target["RemainingAncestor"] = Json::nullValue;
159 } 171 }
160 172
161 t->Commit(); 173 t->Commit();
174
175 // We can remove the files once the SQLite transaction has been
176 // successfully committed
177 listener_->CommitFilesToRemove();
162 178
163 return true; 179 return true;
164 } 180 }
165 181
166 182