MCPcopy Index your code
hub / github.com/scality/cloudserver / processVersioningState

Function processVersioningState

lib/api/apiUtils/object/versioning.js:195–283  ·  view source on GitHub ↗

* Process state from the master version of an object and the bucket * versioning configuration, return a set of options objects * * @param {object} mst - state of master version, as returned by * getMasterState() * @param {string} vstat - bucket versioning status: 'Enabled' or 'Suspended' * @p

(mst, vstat, nullVersionCompatMode)

Source from the content-addressed store, hash-verified

193 version key, if needed
194 */
195function processVersioningState(mst, vstat, nullVersionCompatMode) {
196 const versioningSuspended = (vstat === 'Suspended');
197 const masterIsNull = mst.exists && (mst.isNull || !mst.versionId);
198
199 if (versioningSuspended) {
200 // versioning is suspended: overwrite the existing null version
201 const options = { versionId: '', isNull: true };
202 if (masterIsNull) {
203 // if the null version exists, clean it up prior to put
204 if (mst.objLocation) {
205 options.dataToDelete = mst.objLocation;
206 }
207 // backward-compat: a null version key may exist even with
208 // a null master (due to S3C-7526), if so, delete it (its
209 // data will be deleted as part of the master cleanup, so
210 // no "deleteData" param is needed)
211 //
212 // "isNull2" attribute is set in master metadata when
213 // null keys are used, which is used as an optimization to
214 // avoid having to check the versioned key since there can
215 // be no more versioned key to clean up
216 if (mst.isNull && mst.versionId && !mst.isNull2) {
217 const delOptions = { versionId: mst.versionId };
218 return { options, delOptions };
219 }
220 return { options };
221 }
222 if (mst.nullVersionId) {
223 // backward-compat: delete the null versioned key and data
224 const delOptions = { versionId: mst.nullVersionId, deleteData: true };
225 if (mst.nullUploadId) {
226 delOptions.replayId = mst.nullUploadId;
227 }
228 return { options, delOptions };
229 }
230 // clean up the eventual null key's location data prior to put
231
232 // NOTE: due to metadata v1 internal format, we cannot guess
233 // from the master key whether there is an associated null
234 // key, because the master key may be removed whenever the
235 // latest version becomes a delete marker. Hence we need to
236 // pessimistically try to get the null key metadata and delete
237 // it if it exists.
238 const delOptions = { versionId: 'null', deleteData: true };
239 return { options, delOptions };
240 }
241
242 // versioning is enabled: create a new version
243 const options = { versioning: true };
244 if (masterIsNull) {
245 // if master is a null version or a non-versioned key,
246 // copy it to a new null key
247 const nullVersionId = (mst.isNull && mst.versionId) ? mst.versionId : nonVersionedObjId;
248 if (nullVersionCompatMode) {
249 options.extraMD = {
250 nullVersionId,
251 };
252 if (mst.uploadId) {

Callers 2

versioningPreprocessingFunction · 0.85
versioning.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected