Merge branch '13453-r-sdk-incorrect-rest-call-fix'
[arvados.git] / sdk / R / R / CollectionTree.R
index e024f5eb0f1802703d267b04693dd905876af081..91e4ec86459dc8e4ad8891d59cbdb80d771a4013 100644 (file)
@@ -1,13 +1,7 @@
 source("./R/Subcollection.R")
-
 source("./R/ArvadosFile.R")
+source("./R/util.R")
 
-#' Arvados Collection Object
-#'
-#' Update description
-#'
-#' @examples arv = Collection$new(api, uuid)
-#' @export CollectionTree
 CollectionTree <- R6::R6Class(
     "CollectionTree",
     public = list(
@@ -37,6 +31,9 @@ CollectionTree <- R6::R6Class(
 
         getElement = function(relativePath)
         {
+            relativePath <- trimFromStart(relativePath, "./")
+            relativePath <- trimFromEnd(relativePath, "/")
+
             if(endsWith(relativePath, "/"))
                 relativePath <- substr(relativePath, 0, nchar(relativePath) - 1)
 
@@ -93,6 +90,11 @@ CollectionTree <- R6::R6Class(
             }
             else
             {
+                # Note: REST always returns folder name alone before other folder 
+                # content, so in first iteration we don't know if it's a file
+                # or folder since its just a name, so we assume it's a file. 
+                # If we encounter that same name again we know 
+                # it's a folder so we need to replace ArvadosFile with Subcollection.
                 if("ArvadosFile" %in% class(child))
                 {
                     child = private$replaceFileWithSubcollection(child)