getNullVersionFromMaster - retrieves the null version * metadata via retrieving the master key * * Used in the following cases: * * - master key is non-versioned (and hence is the 'null' version) * * - the null version is stored in a versioned key and its reference * is in the master key a
(bucketName, objectKey, log, cb)
| 93 | * @return {undefined} |
| 94 | */ |
| 95 | function getNullVersionFromMaster(bucketName, objectKey, log, cb) { |
| 96 | async.waterfall([ |
| 97 | next => metadata.getObjectMD(bucketName, objectKey, {}, log, next), |
| 98 | (masterMD, next) => { |
| 99 | if (masterMD.isNull || !masterMD.versionId) { |
| 100 | log.debug('null version is master version'); |
| 101 | return process.nextTick(() => next(null, masterMD)); |
| 102 | } |
| 103 | if (masterMD.nullVersionId) { |
| 104 | // the latest version is not the null version, but null version exists |
| 105 | // NOTE: for backward-compat with old null version scheme |
| 106 | log.debug('get the null version via nullVersionId'); |
| 107 | const getOptions = { |
| 108 | versionId: masterMD.nullVersionId, |
| 109 | }; |
| 110 | return metadata.getObjectMD(bucketName, objectKey, getOptions, log, next); |
| 111 | } |
| 112 | return next(errors.NoSuchKey); |
| 113 | }, |
| 114 | ], (err, nullMD) => { |
| 115 | if (err && err.is && err.is.NoSuchKey) { |
| 116 | log.debug('could not find a null version'); |
| 117 | return cb(); |
| 118 | } |
| 119 | if (err) { |
| 120 | log.debug('err getting object MD from metadata', { error: err }); |
| 121 | return cb(err); |
| 122 | } |
| 123 | return cb(null, nullMD); |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | /** metadataGetObject - retrieves specified object or version from metadata |
| 128 | * @param {string} bucketName - name of bucket |
no test coverage detected