@@ -189,7 +189,7 @@ impl Sub60Cache {
189189 nar_file_name : NarFileName ,
190190 upload_id : & UploadId ,
191191 etags : SmallVec < [ Etag ; 8 ] > ,
192- ) -> Result < ( ) , CacheRequestError > {
192+ ) -> Result < bool , CacheRequestError > {
193193 let url = self . nar_multiparts_complete_url ( upload_id) ;
194194
195195 let response = self
@@ -203,15 +203,15 @@ impl Sub60Cache {
203203 source,
204204 } ) ?;
205205
206- if response. status ( ) . is_success ( ) {
207- Ok ( ( ) )
208- } else {
209- Err ( CacheRequestError :: unexpected_response (
206+ match response. status ( ) {
207+ StatusCode :: CREATED => Ok ( true ) ,
208+ StatusCode :: OK => Ok ( false ) ,
209+ _ => Err ( CacheRequestError :: unexpected_response (
210210 response,
211211 Method :: POST ,
212212 url,
213213 )
214- . await )
214+ . await ) ,
215215 }
216216 }
217217
@@ -480,22 +480,25 @@ impl context::Cache for Sub60Cache {
480480 async fn upload_nar (
481481 & self ,
482482 nar_file_name : NarFileName ,
483- _nar_size : NonZeroU64 ,
483+ nar_size : NonZeroU64 ,
484484 nar_bytes : impl AsyncRead + Send + ' static ,
485- ) -> Result < ( ) , Self :: Error > {
485+ ) -> Result < u64 , Self :: Error > {
486486 let initiate_body =
487487 self . initiate_multipart_nar_upload ( & nar_file_name) . await ?;
488488
489489 let etags = self
490490 . upload_nar_multiparts ( & nar_file_name, & initiate_body, nar_bytes)
491491 . await ?;
492492
493- self . complete_multipart_nar_upload (
494- nar_file_name,
495- & initiate_body. upload_id ,
496- etags,
497- )
498- . await
493+ let did_insert = self
494+ . complete_multipart_nar_upload (
495+ nar_file_name,
496+ & initiate_body. upload_id ,
497+ etags,
498+ )
499+ . await ?;
500+
501+ Ok ( if did_insert { nar_size. get ( ) } else { 0 } )
499502 }
500503
501504 async fn upload_narinfo (
@@ -517,15 +520,15 @@ impl context::Cache for Sub60Cache {
517520 } ,
518521 ) ?;
519522
520- if response. status ( ) . is_success ( ) {
521- Ok ( narinfo_size)
522- } else {
523- Err ( CacheRequestError :: unexpected_response (
523+ match response. status ( ) {
524+ StatusCode :: CREATED => Ok ( narinfo_size) ,
525+ StatusCode :: OK => Ok ( 0 ) ,
526+ _ => Err ( CacheRequestError :: unexpected_response (
524527 response,
525528 Method :: PUT ,
526529 url,
527530 )
528- . await )
531+ . await ) ,
529532 }
530533 }
531534}
0 commit comments