Browse Source

cloud drive: gcs simplify a little bit

pull/2280/head
Chris Lu 3 years ago
parent
commit
12631a3f5b
  1. 12
      weed/remote_storage/gcs/gcs_storage_client.go

12
weed/remote_storage/gcs/gcs_storage_client.go

@ -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)

Loading…
Cancel
Save