Implement copy method, update move method and remove trailing
[arvados.git] / sdk / R / R / RESTService.R
index 867665299f49899909167c4fd838bc9ae1371dd8..78b2c35e32fa117190f033075e1ea5ee2a3805e3 100644 (file)
@@ -81,10 +81,10 @@ RESTService <- R6::R6Class(
         {
             collectionURL <- paste0(self$getWebDavHostName(), "c=", uuid, "/")
             fromURL <- paste0(collectionURL, from)
-            toURL <- paste0(collectionURL, to)
+            toURL <- paste0(collectionURL, trimFromStart(to, "/"))
 
             headers <- list("Authorization" = paste("OAuth2", self$token),
-                           "Destination" = toURL)
+                            "Destination" = toURL)
 
             serverResponse <- self$http$exec("MOVE", fromURL, headers,
                                              retryTimes = self$numRetries)
@@ -95,6 +95,24 @@ RESTService <- R6::R6Class(
             serverResponse
         },
 
+        copy = function(from, to, uuid)
+        {
+            collectionURL <- paste0(self$getWebDavHostName(), "c=", uuid, "/")
+            fromURL <- paste0(collectionURL, from)
+            toURL <- paste0(collectionURL, trimFromStart(to, "/"))
+
+            headers <- list("Authorization" = paste("OAuth2", self$token),
+                            "Destination" = toURL)
+
+            serverResponse <- self$http$exec("COPY", fromURL, headers,
+                                             retryTimes = self$numRetries)
+
+            if(serverResponse$status_code < 200 || serverResponse$status_code >= 300)
+                stop(paste("Server code:", serverResponse$status_code))
+
+            serverResponse
+        },
+
         getCollectionContent = function(uuid)
         {
             collectionURL <- URLencode(paste0(self$getWebDavHostName(),