tustvold commented on code in PR #4759:
URL: https://github.com/apache/arrow-rs/pull/4759#discussion_r1312876239


##########
object_store/src/http/client.rs:
##########
@@ -256,31 +256,37 @@ impl Client {
     }
 
     pub async fn copy(&self, from: &Path, to: &Path, overwrite: bool) -> 
Result<()> {
-        let from = self.path_url(from);
-        let to = self.path_url(to);
-        let method = Method::from_bytes(b"COPY").unwrap();
-
-        let mut builder = self
-            .client
-            .request(method, from)
-            .header("Destination", to.as_str());
+        let mut retry = false;
+        loop {
+            let method = Method::from_bytes(b"COPY").unwrap();
 
-        if !overwrite {
-            builder = builder.header("Overwrite", "F");
-        }
+            let mut builder = self
+                .client
+                .request(method, self.path_url(from))
+                .header("Destination", self.path_url(to).as_str());
 
-        match builder.send_retry(&self.retry_config).await {
-            Ok(_) => Ok(()),
-            Err(e)
-                if !overwrite
-                    && matches!(e.status(), 
Some(StatusCode::PRECONDITION_FAILED)) =>
-            {
-                Err(crate::Error::AlreadyExists {
-                    path: to.to_string(),
-                    source: Box::new(e),
-                })
+            if !overwrite {
+                builder = builder.header("Overwrite", "F");
             }
-            Err(source) => Err(Error::Request { source }.into()),
+
+            return match builder.send_retry(&self.retry_config).await {
+                Ok(_) => Ok(()),
+                Err(source) => Err(match source.status() {
+                    Some(StatusCode::PRECONDITION_FAILED) if !overwrite => {
+                        crate::Error::AlreadyExists {
+                            path: to.to_string(),
+                            source: Box::new(source),
+                        }
+                    }
+                    // Some implementations return 404 instead of 409
+                    Some(StatusCode::CONFLICT | StatusCode::NOT_FOUND) if 
!retry => {
+                        retry = true;

Review Comment:
   We copy the loop protection from the other http methods, this is necessary 
here because HTTP implementations may return StatusCode::Conflict for other 
reasons



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to