@@ -147,10 +147,12 @@ impl Sub60Cache {
147147 Ok ( Self { cache_url, client, spawner } )
148148 }
149149
150+ /// Initiates a multipart upload for the given NAR, returning `None` if the
151+ /// cache already contains it.
150152 async fn initiate_multipart_nar_upload (
151153 & self ,
152154 nar_file_name : & NarFileName ,
153- ) -> Result < NarMultipartsResponseBody , CacheRequestError > {
155+ ) -> Result < Option < NarMultipartsResponseBody > , CacheRequestError > {
154156 let url = self . nar_multiparts_url ( ) ;
155157
156158 let response = self
@@ -164,13 +166,17 @@ impl Sub60Cache {
164166 source,
165167 } ) ?;
166168
167- if !response. status ( ) . is_success ( ) {
168- return Err ( CacheRequestError :: unexpected_response (
169- response,
170- Method :: POST ,
171- url,
172- )
173- . await ) ;
169+ match response. status ( ) {
170+ StatusCode :: OK => { } ,
171+ StatusCode :: NO_CONTENT => return Ok ( None ) ,
172+ _ => {
173+ return Err ( CacheRequestError :: unexpected_response (
174+ response,
175+ Method :: POST ,
176+ url,
177+ )
178+ . await ) ;
179+ } ,
174180 }
175181
176182 response
@@ -181,6 +187,7 @@ impl Sub60Cache {
181187 source,
182188 } ) ?
183189 . parse :: < NarMultipartsResponseBody > ( )
190+ . map ( Some )
184191 . map_err ( CacheRequestError :: ParseNarMultipartsResponseBody )
185192 }
186193
@@ -483,8 +490,11 @@ impl context::Cache for Sub60Cache {
483490 nar_size : NonZeroU64 ,
484491 nar_bytes : impl AsyncRead + Send + ' static ,
485492 ) -> Result < u64 , Self :: Error > {
486- let initiate_body =
487- self . initiate_multipart_nar_upload ( & nar_file_name) . await ?;
493+ let Some ( initiate_body) =
494+ self . initiate_multipart_nar_upload ( & nar_file_name) . await ?
495+ else {
496+ return Ok ( 0 ) ;
497+ } ;
488498
489499 let etags = self
490500 . upload_nar_multiparts ( & nar_file_name, & initiate_body, nar_bytes)
0 commit comments