cloud drive: gcs simplify a little bit

This commit is contained in:
Chris Lu 2021-08-23 14:43:01 -07:00
parent 95a6e0226d
commit 12631a3f5b

View file

@ -110,24 +110,16 @@ func (gcs *gcsRemoteStorageClient) WriteFile(loc *filer_pb.RemoteStorageLocation
key := loc.Path[1:]
metadata := toMetadata(entry.Extended)
wc := gcs.client.Bucket(loc.Bucket).Object(key).NewWriter(context.Background())
wc.Metadata = metadata
if _, err = io.Copy(wc, reader); err != nil {
wc.Close()
return nil, fmt.Errorf("upload to gcs %s/%s%s: %v", loc.Name, loc.Bucket, loc.Path, err)
}
if err = wc.Close(); err != nil {
return nil, fmt.Errorf("close gcs %s/%s%s: %v", loc.Name, loc.Bucket, loc.Path, err)
}
metadata := toMetadata(entry.Extended)
if len(metadata) > 0 {
if _, err = gcs.client.Bucket(loc.Bucket).Object(key).Update(context.Background(), storage.ObjectAttrsToUpdate{
Metadata: metadata,
}); err != nil {
return nil, fmt.Errorf("update metadata gcs %s/%s%s: %v", loc.Name, loc.Bucket, loc.Path, err)
}
}
// read back the remote entry
return gcs.readFileRemoteEntry(loc)