-
Notifications
You must be signed in to change notification settings - Fork 601
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
feat(storage): support gs:// copy/move dests #1416
Conversation
Preferences for how to address the lint error (line length >80 chars)? Could break before the callback, move the dest string to a variable, shorten some names... -- all of which break the pattern of the other usage examples. |
Thanks! Will check this out tomorrow. |
* // If you pass in a string starting with "gs://" for the destination, the | ||
* // file is copied to the other bucket and under the new name provided. | ||
* //- | ||
* file.copy('gs://other-bucket/my-image-copy.png', function(err, copiedFile, apiResponse) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
LGTM. Would you mind adding a system test? You can add one after this, "it should copy an existing file with a GS URL" (or something similar) If you haven't run the system tests before, we have a guide on setting the right env vars: https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/CONTRIBUTING.md#system-tests Also, running the test will create a bucket and file under your account (then delete them), so it's understandable if you'd rather not run the tests. If you do, make sure you change the test you're working on to read: it.only('...', function() {}) The |
Thanks for your review. On the system test, how would you like to handle file/bucket cleanup? You have a special Also, is it unnecessary to assert on the contents of the other bucket? it.only('should copy to another bucket given a gs:// URL', function(done) {
var opts = { destination: 'CloudLogo' };
bucket.upload(FILES.logo.path, opts, function(err, file) {
assert.ifError(err);
var otherBucket = storage.bucket(generateName());
otherBucket.create(function (err) {
assert.ifError(err);
var destPath = 'gs://' + otherBucket.name + '/CloudLogoCopy';
file.copy(destPath, function(err, copiedFile) {
assert.ifError(err);
otherBucket.getFiles(function (err, files) { // Necessary? >>
assert.ifError(err);
assert.equal(files.length, 1);
var newFile = files[0];
assert.equal(newFile.name, "CloudLogoCopy"); // << Necessary?
async.parallel([
file.delete.bind(file),
newFile.delete.bind(newFile),
otherBucket.delete.bind(otherBucket) // Needs eventual consistency protection
], done);
});
});
});
});
}); |
For bucket cleanup, you can let the And I like that you're checking that the new bucket received the file 👍 I'll just have some linting notes, but LGTM. |
destName = destination; | ||
var parsedDestination = GS_URL_REGEXP.exec(destination); | ||
if (parsedDestination !== null && parsedDestination.length === 3) { | ||
destBucket = this.storage.bucket(parsedDestination[1]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Sorry about all that, my linter apparently decided to retire. |
assert.strictEqual(files.length, 1); | ||
var newFile = files[0]; | ||
|
||
assert.equal(newFile.name, 'CloudLogoCopy'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Haha, I'm sorry that I have to even comment on this little stuff. I wish it could just be auto-formatted. |
Squashed together... managed to swamp travis though 😢 |
No problem. I canceled the queued, old builds. |
Perfect! We intend to get a release out shortly with support for Bigtable (currently held up on #1424), so this will ship with that. Thanks very much :) |
Fixes #1395 -- supports gs:// strings for specifying destination buckets.
I'm not totally thrilled with what I did on line 391 but I don't see a better way to create a new Bucket instance from File.js.
The string format testing with
GS_URL_REGEXP.exec
is both more specific and faster than usingdestination.indexOf("gs://")
.