-
Notifications
You must be signed in to change notification settings - Fork 641
storage: support specifying a generation #409
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: support specifying a generation #409
Conversation
lib/storage/file.js
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Yes, we should use ifGenerationMatch. And the API call can fail, and they can handle that in some way.
Nope I think if they specify a generation, keep it at that generation. If they don't specify a generation, it always represents the latest version. If they specify a generation that HAPPENS to be the current generation, still keep it at that generation. |
|
I think generation is an edge-case so having it fail in most scenarios is okay, only when it makes the most sense to use, should it be used. Also instead of trying to figure out or guess how it will be used by developers, I say delegate the logic to the API. |
d8e3b84 to
7d4ada1
Compare
7d4ada1 to
af68169
Compare
|
Revisiting this one to clean up the PR queue. Issues were resolved. Most importantly, versioning has to be enabled at the bucket level. We can perhaps create a convenience method for this ( storage.createBucket('name', {
versioning: {
enabled: true
}
})
storage.bucket('name').setMetadata({
versioning: {
enabled: true
}
})Either way, writing some tests and will ping when it's ready for a closer look. |
af68169 to
f871220
Compare
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
7d6161b to
d464c7b
Compare
|
This is ready for a closer review. Calling // @javorosas |
8178bcd to
3aa2fae
Compare
|
Seems the tests are failing? |
3aa2fae to
4614265
Compare
|
Not anymore! |
lib/storage/file.js
Outdated
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Fixes #406
Fixes #498
This is a first attempt at allowing a user to lock a File instance to a generation:
Issue 1Resolved 👍
#409 (comment)
How should normal operations on a File be changed to match a file locked to a generation?
These are pretty straightforward:
copy()- specifysourceGenerationin the querycreateReadStream()/download()- specifygenerationin the querydelete()- specifygenerationin the querygetMetadata()- specifygenerationin the querysetMetadata()- specifygenerationin the queryHowever, when you update the file with
createWriteStream(), it usesifGenerationMatchin the query to mean: only write to this file if the current generation on the remote file is the same as the generation specified for the File instance. So, if you're 3 generations back trying to update the file, it wouldn't work.ifGenerationMatchin this way or should we just let the user write to the file regardless?Issue 2Resolved 👍
Bucket must be created with
{versioning: { enabled: true }}.This has also been difficult to test with the real API. Here is a script I wrote to attempt to create a file, update it, then access its first state:
But that results in:
I can use
bucket.file(fileName, { generation: /* b's value */ })fine, but I can't get a's. I'm inclined to believe this is me not understanding how to use generations, and not a bug in the code.