@@ -65,11 +65,11 @@ public class CopyWriter implements Restorable<CopyWriter> {
6565 *
6666 * @throws StorageException upon failure
6767 */
68- public BlobInfo result () {
68+ public Blob result () {
6969 while (!isDone ()) {
7070 copyChunk ();
7171 }
72- return BlobInfo .fromPb (rewriteResponse .result );
72+ return Blob .fromPb (serviceOptions . service (), rewriteResponse .result );
7373 }
7474
7575 /**
@@ -120,8 +120,12 @@ public RestorableState<CopyWriter> capture() {
120120 serviceOptions ,
121121 BlobId .fromPb (rewriteResponse .rewriteRequest .source ),
122122 rewriteResponse .rewriteRequest .sourceOptions ,
123- BlobInfo .fromPb (rewriteResponse .rewriteRequest .target ),
123+ BlobId .of (rewriteResponse .rewriteRequest .targetBucket ,
124+ rewriteResponse .rewriteRequest .targetName ),
124125 rewriteResponse .rewriteRequest .targetOptions )
126+ .targetInfo (rewriteResponse .rewriteRequest .targetObject != null
127+ ? BlobInfo .fromPb (rewriteResponse .rewriteRequest .targetObject ) : null )
128+ .result (rewriteResponse .result != null ? BlobInfo .fromPb (rewriteResponse .result ) : null )
125129 .blobSize (blobSize ())
126130 .isDone (isDone ())
127131 .megabytesCopiedPerChunk (rewriteResponse .rewriteRequest .megabytesRewrittenPerCall )
@@ -132,12 +136,13 @@ public RestorableState<CopyWriter> capture() {
132136
133137 static class StateImpl implements RestorableState <CopyWriter >, Serializable {
134138
135- private static final long serialVersionUID = 8279287678903181701L ;
139+ private static final long serialVersionUID = 1693964441435822700L ;
136140
137141 private final StorageOptions serviceOptions ;
138142 private final BlobId source ;
139143 private final Map <StorageRpc .Option , ?> sourceOptions ;
140- private final BlobInfo target ;
144+ private final BlobId targetId ;
145+ private final BlobInfo targetInfo ;
141146 private final Map <StorageRpc .Option , ?> targetOptions ;
142147 private final BlobInfo result ;
143148 private final long blobSize ;
@@ -150,7 +155,8 @@ static class StateImpl implements RestorableState<CopyWriter>, Serializable {
150155 this .serviceOptions = builder .serviceOptions ;
151156 this .source = builder .source ;
152157 this .sourceOptions = builder .sourceOptions ;
153- this .target = builder .target ;
158+ this .targetId = builder .targetId ;
159+ this .targetInfo = builder .targetInfo ;
154160 this .targetOptions = builder .targetOptions ;
155161 this .result = builder .result ;
156162 this .blobSize = builder .blobSize ;
@@ -165,8 +171,9 @@ static class Builder {
165171 private final StorageOptions serviceOptions ;
166172 private final BlobId source ;
167173 private final Map <StorageRpc .Option , ?> sourceOptions ;
168- private final BlobInfo target ;
174+ private final BlobId targetId ;
169175 private final Map <StorageRpc .Option , ?> targetOptions ;
176+ private BlobInfo targetInfo ;
170177 private BlobInfo result ;
171178 private long blobSize ;
172179 private boolean isDone ;
@@ -176,14 +183,19 @@ static class Builder {
176183
177184 private Builder (StorageOptions options , BlobId source ,
178185 Map <StorageRpc .Option , ?> sourceOptions ,
179- BlobInfo target , Map <StorageRpc .Option , ?> targetOptions ) {
186+ BlobId targetId , Map <StorageRpc .Option , ?> targetOptions ) {
180187 this .serviceOptions = options ;
181188 this .source = source ;
182189 this .sourceOptions = sourceOptions ;
183- this .target = target ;
190+ this .targetId = targetId ;
184191 this .targetOptions = targetOptions ;
185192 }
186193
194+ Builder targetInfo (BlobInfo targetInfo ) {
195+ this .targetInfo = targetInfo ;
196+ return this ;
197+ }
198+
187199 Builder result (BlobInfo result ) {
188200 this .result = result ;
189201 return this ;
@@ -220,15 +232,16 @@ RestorableState<CopyWriter> build() {
220232 }
221233
222234 static Builder builder (StorageOptions options , BlobId source ,
223- Map <StorageRpc .Option , ?> sourceOptions , BlobInfo target ,
235+ Map <StorageRpc .Option , ?> sourceOptions , BlobId targetId ,
224236 Map <StorageRpc .Option , ?> targetOptions ) {
225- return new Builder (options , source , sourceOptions , target , targetOptions );
237+ return new Builder (options , source , sourceOptions , targetId , targetOptions );
226238 }
227239
228240 @ Override
229241 public CopyWriter restore () {
230- RewriteRequest rewriteRequest = new RewriteRequest (
231- source .toPb (), sourceOptions , target .toPb (), targetOptions , megabytesCopiedPerChunk );
242+ RewriteRequest rewriteRequest = new RewriteRequest (source .toPb (), sourceOptions ,
243+ targetId .bucket (), targetId .name (), targetInfo != null ? targetInfo .toPb () : null ,
244+ targetOptions , megabytesCopiedPerChunk );
232245 RewriteResponse rewriteResponse = new RewriteResponse (rewriteRequest ,
233246 result != null ? result .toPb () : null , blobSize , isDone , rewriteToken ,
234247 totalBytesCopied );
@@ -237,8 +250,9 @@ public CopyWriter restore() {
237250
238251 @ Override
239252 public int hashCode () {
240- return Objects .hash (serviceOptions , source , sourceOptions , target , targetOptions , result ,
241- blobSize , isDone , megabytesCopiedPerChunk , rewriteToken , totalBytesCopied );
253+ return Objects .hash (serviceOptions , source , sourceOptions , targetId , targetInfo ,
254+ targetOptions , result , blobSize , isDone , megabytesCopiedPerChunk , rewriteToken ,
255+ totalBytesCopied );
242256 }
243257
244258 @ Override
@@ -253,7 +267,8 @@ public boolean equals(Object obj) {
253267 return Objects .equals (this .serviceOptions , other .serviceOptions )
254268 && Objects .equals (this .source , other .source )
255269 && Objects .equals (this .sourceOptions , other .sourceOptions )
256- && Objects .equals (this .target , other .target )
270+ && Objects .equals (this .targetId , other .targetId )
271+ && Objects .equals (this .targetInfo , other .targetInfo )
257272 && Objects .equals (this .targetOptions , other .targetOptions )
258273 && Objects .equals (this .result , other .result )
259274 && Objects .equals (this .rewriteToken , other .rewriteToken )
@@ -267,10 +282,14 @@ public boolean equals(Object obj) {
267282 public String toString () {
268283 return MoreObjects .toStringHelper (this )
269284 .add ("source" , source )
270- .add ("target " , target )
271- .add ("isDone " , isDone )
272- .add ("totalBytesRewritten " , totalBytesCopied )
285+ .add ("targetId " , targetId )
286+ .add ("targetInfo " , targetInfo )
287+ .add ("result " , result )
273288 .add ("blobSize" , blobSize )
289+ .add ("isDone" , isDone )
290+ .add ("rewriteToken" , rewriteToken )
291+ .add ("totalBytesCopied" , totalBytesCopied )
292+ .add ("megabytesCopiedPerChunk" , megabytesCopiedPerChunk )
274293 .toString ();
275294 }
276295 }
0 commit comments