Compare commits

...

1 Commits

Author SHA1 Message Date
Jonathan Gramain c25a115da3 S3C-7352 proto 2023-02-21 20:36:42 -08:00
1 changed files with 54 additions and 17 deletions

View File

@ -30,6 +30,7 @@ class DelimiterVersions extends Delimiter {
// internal state // internal state
this.masterKey = undefined; this.masterKey = undefined;
this.masterVersionId = undefined; this.masterVersionId = undefined;
this.nullKey = null;
// listing results // listing results
this.NextMarker = parameters.keyMarker; this.NextMarker = parameters.keyMarker;
this.NextVersionIdMarker = undefined; this.NextVersionIdMarker = undefined;
@ -190,10 +191,6 @@ class DelimiterVersions extends Delimiter {
* @return {number} - indicates if iteration should continue * @return {number} - indicates if iteration should continue
*/ */
filterV1(obj) { filterV1(obj) {
if (Version.isPHD(obj.value)) {
// return accept to avoid skipping the next values in range
return FILTER_ACCEPT;
}
// this function receives both M and V keys, but their prefix // this function receives both M and V keys, but their prefix
// length is the same so we can remove their prefix without // length is the same so we can remove their prefix without
// looking at the type of key // looking at the type of key
@ -205,24 +202,13 @@ class DelimiterVersions extends Delimiter {
if (this.prefix && !key.startsWith(this.prefix)) { if (this.prefix && !key.startsWith(this.prefix)) {
return FILTER_SKIP; return FILTER_SKIP;
} }
let nonversionedKey;
let versionId = undefined; let versionId = undefined;
const versionIdIndex = key.indexOf(VID_SEP); const versionIdIndex = key.indexOf(VID_SEP);
if (versionIdIndex < 0) { let nonversionedKey;
if (versionIdIndex === -1) {
nonversionedKey = key; nonversionedKey = key;
this.masterKey = key;
this.masterVersionId =
Version.from(value).getVersionId() || 'null';
versionId = this.masterVersionId;
} else { } else {
nonversionedKey = key.slice(0, versionIdIndex); nonversionedKey = key.slice(0, versionIdIndex);
versionId = key.slice(versionIdIndex + 1);
// skip a version key if it is the master version
if (this.masterKey === nonversionedKey && this.masterVersionId === versionId) {
return FILTER_SKIP;
}
this.masterKey = undefined;
this.masterVersionId = undefined;
} }
if (this.delimiter) { if (this.delimiter) {
const baseIndex = this.prefix ? this.prefix.length : 0; const baseIndex = this.prefix ? this.prefix.length : 0;
@ -231,6 +217,49 @@ class DelimiterVersions extends Delimiter {
return this.addCommonPrefix(nonversionedKey, delimiterIndex); return this.addCommonPrefix(nonversionedKey, delimiterIndex);
} }
} }
if (versionIdIndex === -1) {
this.masterKey = key;
this.masterVersionId =
Version.from(value).getVersionId() || 'null';
versionId = this.masterVersionId;
if (this.nullKey && this.nullKey.nonversionedKey !== key) {
this.addContents({
key: this.nullKey.nonversionedKey,
value: this.nullKey.value,
versionId: this.nullKey.versionId,
});
this.nullKey = null;
}
} else {
versionId = key.slice(versionIdIndex + 1);
// regular version key
if (this.nullKey &&
(this.nullKey.nonversionedKey !== nonversionedKey
|| this.nullKey.versionId < versionId)) {
this.addContents({
key: this.nullKey.nonversionedKey,
value: this.nullKey.value,
versionId: this.nullKey.versionId,
});
this.nullKey = null;
}
if (versionId === '') {
// null key
versionId = Version.from(value).getVersionId();
this.nullKey = {
nonversionedKey,
versionId,
value,
};
return FILTER_ACCEPT;
}
if (this.masterKey === nonversionedKey && this.masterVersionId === versionId) {
// do not add a version key if it is the master version
return FILTER_SKIP;
}
this.masterKey = undefined;
this.masterVersionId = undefined;
}
return this.addContents({ key: nonversionedKey, value, versionId }); return this.addContents({ key: nonversionedKey, value, versionId });
} }
@ -268,6 +297,14 @@ class DelimiterVersions extends Delimiter {
* specified in v1 listing documentation * specified in v1 listing documentation
* http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html * http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGET.html
*/ */
if (this.nullKey) {
this.addContents({
key: this.nullKey.nonversionedKey,
value: this.nullKey.value,
versionId: this.nullKey.versionId,
});
this.nullKey = null;
}
return { return {
CommonPrefixes: this.CommonPrefixes, CommonPrefixes: this.CommonPrefixes,
Versions: this.Contents, Versions: this.Contents,