Skip to content

Commit

Permalink
fix: force setMetadata calls to use promise version, invoke callbacks…
Browse files Browse the repository at this point in the history
… manually (#2000)

* fix: correctly handle an empty file in download function

* remove accidental import

* fix: force setMetadata calls to use promise version, invoke callbacks manually

* remove unused import

* spread the response from setMetadata while invoking callback
  • Loading branch information
ddelgrosso1 committed Jul 13, 2022
1 parent cb62721 commit f488647
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 128 deletions.
132 changes: 79 additions & 53 deletions src/bucket.ts
Expand Up @@ -1301,8 +1301,12 @@ class Bucket extends ServiceObject {
);

if (options.append === false) {
this.setMetadata({lifecycle: {rule: newLifecycleRules}}, callback);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata({lifecycle: {rule: newLifecycleRules}})
.then(resp => callback!(null, ...resp))
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
return;
}

Expand All @@ -1318,16 +1322,17 @@ class Bucket extends ServiceObject {
metadata.lifecycle && metadata.lifecycle.rule
);

this.setMetadata(
{
lifecycle: {
rule: currentLifecycleRules.concat(newLifecycleRules),
},
this.setMetadata({
lifecycle: {
rule: currentLifecycleRules.concat(newLifecycleRules),
},
callback!
);
})
.then(resp => callback!(null, ...resp))
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
});
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
}

combine(
Expand Down Expand Up @@ -2097,19 +2102,22 @@ class Bucket extends ServiceObject {
disableRequesterPays(
callback?: DisableRequesterPaysCallback
): Promise<DisableRequesterPaysResponse> | void {
const cb = callback || util.noop;
this.disableAutoRetryConditionallyIdempotent_(
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata(
{
billing: {
requesterPays: false,
},

this.setMetadata({
billing: {
requesterPays: false,
},
callback || util.noop
);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
})
.then(resp => cb(null, ...resp))
.catch(cb)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

enableLogging(
Expand Down Expand Up @@ -2277,19 +2285,21 @@ class Bucket extends ServiceObject {
enableRequesterPays(
callback?: EnableRequesterPaysCallback
): Promise<EnableRequesterPaysResponse> | void {
const cb = callback || util.noop;
this.disableAutoRetryConditionallyIdempotent_(
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata(
{
billing: {
requesterPays: true,
},
this.setMetadata({
billing: {
requesterPays: true,
},
callback || util.noop
);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
})
.then(resp => cb(null, ...resp))
.catch(cb)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

/**
Expand Down Expand Up @@ -3098,7 +3108,8 @@ class Bucket extends ServiceObject {
}
return [];
})
.then(files => callback!(null, files), callback!)
.then(files => callback!(null, files))
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
Expand Down Expand Up @@ -3288,17 +3299,19 @@ class Bucket extends ServiceObject {
removeRetentionPeriod(
callback?: SetBucketMetadataCallback
): Promise<SetBucketMetadataResponse> | void {
const cb = callback || util.noop;
this.disableAutoRetryConditionallyIdempotent_(
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata(
{
retentionPolicy: null,
},
callback!
);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata({
retentionPolicy: null,
})
.then(resp => cb(null, ...resp))
.catch(cb)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

request(reqOpts: DecorateRequestOptions): Promise<[ResponseBody, Metadata]>;
Expand Down Expand Up @@ -3403,8 +3416,12 @@ class Bucket extends ServiceObject {
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata({labels}, options, callback);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata({labels}, options)
.then(resp => callback!(null, ...resp))
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

setRetentionPeriod(duration: number): Promise<SetBucketMetadataResponse>;
Expand Down Expand Up @@ -3453,19 +3470,21 @@ class Bucket extends ServiceObject {
duration: number,
callback?: SetBucketMetadataCallback
): Promise<SetBucketMetadataResponse> | void {
const cb = callback || util.noop;
this.disableAutoRetryConditionallyIdempotent_(
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata(
{
retentionPolicy: {
retentionPeriod: duration,
},
this.setMetadata({
retentionPolicy: {
retentionPeriod: duration,
},
callback!
);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
})
.then(resp => cb(null, ...resp))
.catch(cb)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

setCorsConfiguration(
Expand Down Expand Up @@ -3524,17 +3543,20 @@ class Bucket extends ServiceObject {
corsConfiguration: Cors[],
callback?: SetBucketMetadataCallback
): Promise<SetBucketMetadataResponse> | void {
const cb = callback || util.noop;
this.disableAutoRetryConditionallyIdempotent_(
this.methods.setMetadata,
AvailableServiceObjectMethods.setMetadata
);
this.setMetadata(
{
cors: corsConfiguration,
},
callback!
);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;

this.setMetadata({
cors: corsConfiguration,
})
.then(resp => cb(null, ...resp))
.catch(cb)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

setStorageClass(
Expand Down Expand Up @@ -3619,8 +3641,12 @@ class Bucket extends ServiceObject {
})
.toUpperCase();

this.setMetadata({storageClass}, options, callback!);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata({storageClass}, options)
.then(() => callback!())
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/file.ts
Expand Up @@ -3018,8 +3018,12 @@ class File extends ServiceObject<File> {
// file.
const metadata = extend({}, options.metadata, {acl: null});

this.setMetadata(metadata, query, callback!);
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
this.setMetadata(metadata, query)
.then(resp => callback!(null, ...resp))
.catch(callback!)
.finally(() => {
this.storage.retryOptions.autoRetry = this.instanceRetryValue;
});
}

makePublic(): Promise<MakeFilePublicResponse>;
Expand Down

0 comments on commit f488647

Please sign in to comment.