From 680dbccd58afc1ca650f5c20e9d84568a9c582b2 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 12 Oct 2018 11:05:04 +0200 Subject: [PATCH] do not ignore document revision (#6851) --- arangod/RestHandler/RestDocumentHandler.cpp | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index 0cfda26ef7..fd39340d22 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -212,8 +212,7 @@ bool RestDocumentHandler::readSingleDocument(bool generateBody) { TRI_voc_rid_t ifRid = extractRevision("if-match", isValidRevision); if (!isValidRevision) { - ifRid = - UINT64_MAX; // an impossible rev, so precondition failed will happen + ifRid = UINT64_MAX; // an impossible rev, so precondition failed will happen } VPackBuilder builder; @@ -382,14 +381,18 @@ bool RestDocumentHandler::modifyDocument(bool isPatch) { // extract the revision, if single document variant and header given: std::shared_ptr builder; if (!isArrayCase) { - TRI_voc_rid_t revision = 0; bool isValidRevision; - revision = extractRevision("if-match", isValidRevision); + TRI_voc_rid_t headerRev = extractRevision("if-match", isValidRevision); if (!isValidRevision) { - revision = UINT64_MAX; // an impossible revision, so precondition failed + headerRev = UINT64_MAX; // an impossible revision, so precondition failed } + if (headerRev != 0) { + opOptions.ignoreRevs = false; + } + VPackSlice keyInBody = body.get(StaticStrings::KeyString); - if ((revision != 0 && TRI_ExtractRevisionId(body) != revision) || + TRI_voc_rid_t revInBody = TRI_ExtractRevisionId(body); + if ((headerRev != 0 && revInBody != headerRev) || keyInBody.isNone() || keyInBody.isNull() || (keyInBody.isString() && keyInBody.copyString() != key)) { // We need to rewrite the document with the given revision and key: @@ -398,18 +401,19 @@ bool RestDocumentHandler::modifyDocument(bool isPatch) { VPackObjectBuilder guard(builder.get()); TRI_SanitizeObject(body, *builder); builder->add(StaticStrings::KeyString, VPackValue(key)); - if (revision != 0) { + if (headerRev != 0) { builder->add(StaticStrings::RevString, - VPackValue(TRI_RidToString(revision))); + VPackValue(TRI_RidToString(headerRev))); + } else if (!opOptions.ignoreRevs && revInBody != 0) { + builder->add(StaticStrings::RevString, + VPackValue(TRI_RidToString(headerRev))); } } body = builder->slice(); } - if (revision != 0) { - opOptions.ignoreRevs = false; - } + } // find and load collection given by name or identifier