Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: add deleteFiles() #698

Merged

Conversation

stephenplusplus
Copy link
Contributor

Fixes #680

Docs: http://stephenplusplus.github.io/gcloud-node-gh-pages-again/#/docs/master/storage/bucket?method=deleteFiles

Todos

  • Explain in the docs that this could be costly and is not atomic.
  • Document callback arguments.

This adds a new method on Bucket: deleteFiles.

Old way of deleting all of the files in the bucket. No error handling, no throttling, no paging.

bucket.getFiles(function(err, files) {
  files.forEach(function(file) {
    file.delete();
  });
});

New way with error handling and throttling built in.

bucket.deleteFiles(function(err) {});

Behind the scenes, deleteFiles just calls getFiles. So, you're able to pass your getFiles query object to deleteFiles.

bucket.deleteFiles({ prefix: 'images/' }, function(err) {});

By default, if an error occurs, no more files will be deleted. This can be shut off.

bucket.deleteFiles({ force: true }, function(errors) {
  // errors = null | Error[]
});

@stephenplusplus stephenplusplus added the api: storage Issues related to the Cloud Storage API. label Jun 30, 2015
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 30, 2015
@jgeewax
Copy link
Contributor

jgeewax commented Jul 1, 2015

Sounds good to me. Hopefully later we can have this be atomic. For now, we should make it super clear in the documentation that it isn't atomic, and you might incur cost for a huge number of operations...... (ie, a big warning sign...)

* for all of the supported properties.
* @param {boolean} query.force - Supress errors until all files have been
* processed.
* @param {function} callback - The callback function.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor Author

Ready for another check. Added the docs and also caught some probs with how array params were being displayed. Docs here: http://stephenplusplus.github.io/gcloud-node-gh-pages-again/#/docs/master/storage/bucket?method=deleteFiles

@jgeewax
Copy link
Contributor

jgeewax commented Jul 6, 2015

OK LGTM but maybe @ryanseys should take a look ?

return;
}

// Iterate through each file and make it public or private.

This comment was marked as spam.

@ryanseys
Copy link
Contributor

ryanseys commented Jul 7, 2015

LGTM other than the small comment to be updated. equal vs. strictEqual might be a repo-wide change to be made so if you don't change it in this PR that's nbd. Also you're comparing objects so == should suffice because type inference doesn't do much on an object, but I digress. LGTM.

@stephenplusplus
Copy link
Contributor Author

Thanks for reviewing! I think we have a mixture, but I've been
doing deepEqual lately. Not sure if any of them are really better than the
other, but I'll update it to one of the others before this ships.

On Tuesday, July 7, 2015, Ryan Seys notifications@github.com wrote:

LGTM other than the small comment to be updated. equal vs. strictEqual
might be a repo-wide change to be made so if you don't change it in this PR
that's nbd. Also you're comparing objects so == should suffice because
type inference doesn't do much on an object, but I digress. LGTM.


Reply to this email directly or view it on GitHub
#698 (comment)
.

@ryanseys
Copy link
Contributor

ryanseys commented Jul 7, 2015

equal compares with == so type inference and all that jazz.

deepEqual compares each property of one object with the properties of another object without the objects necessarily being the same object -- good for assert.deepEqual(config, { actual: 'config', goes: 'here })

strictEqual compares with === so either the objects reference the same memory or they are equal primitives.

@ryanseys
Copy link
Contributor

ryanseys commented Jul 7, 2015

I'd say strictEqual should be used in place of equal everywhere and leave deepEqual everywhere else.

@stephenplusplus
Copy link
Contributor Author

Changed to strictEqual (will use in the future) and updated the stale comment.

stephenplusplus added a commit that referenced this pull request Jul 9, 2015
@stephenplusplus stephenplusplus merged commit 7f7c2b1 into googleapis:master Jul 9, 2015
sofisl pushed a commit that referenced this pull request Oct 11, 2022
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 477248447

Source-Link: googleapis/googleapis@4689c73

Source-Link: googleapis/googleapis-gen@c405978
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzQwNTk3ODZhNWNkODA1YTAxNTFkOTViNDc3ZmJjNDg2YmNiY2VkYyJ9

docs: fix docstring formatting
Committer: @parthea
PiperOrigin-RevId: 476410563

Source-Link: googleapis/googleapis@7f579ee

Source-Link: googleapis/googleapis-gen@ae0240e
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWUwMjQwZTA5N2ExOTZjMDcwZTE1ZGVhYWU2NjQ2NGI0MmM4ZTAxNCJ9
sofisl pushed a commit that referenced this pull request Oct 13, 2022
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 477248447

Source-Link: googleapis/googleapis@4689c73

Source-Link: googleapis/googleapis-gen@c405978
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYzQwNTk3ODZhNWNkODA1YTAxNTFkOTViNDc3ZmJjNDg2YmNiY2VkYyJ9

docs: fix docstring formatting
Committer: @parthea
PiperOrigin-RevId: 476410563

Source-Link: googleapis/googleapis@7f579ee

Source-Link: googleapis/googleapis-gen@ae0240e
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWUwMjQwZTA5N2ExOTZjMDcwZTE1ZGVhYWU2NjQ2NGI0MmM4ZTAxNCJ9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cloud Storage Delete all files with prefix
4 participants