--- a/src/mediaserver/cdplugins/uprcl/uprclfolders.py
+++ b/src/mediaserver/cdplugins/uprcl/uprclfolders.py
@@ -25,6 +25,14 @@
 # configuration. The entries are paths instead of simple names, and
 # the doc index (j) is 0. The dir index points normally to a dirvec
 # entry.
+
+# Create new directory entry: insert in father and append dirvec slot (with ".." entry)
+def _createdir(dirvec, fathidx, docidx, nm):
+    dirvec.append({})
+    dirvec[fathidx][nm] = (len(dirvec) - 1, docidx)
+    dirvec[-1][".."] = (fathidx, -1)
+    return len(dirvec) - 1
+
 def _rcl2folders(docs, confdir):
     global dirvec
     dirvec = []
@@ -33,12 +41,12 @@
     topdirs = [os.path.expanduser(d) for d in
                shlex.split(rclconf.getConfParam('topdirs'))]
 
-    topidx = 0
     dirvec.append({})
+    dirvec[0][".."] = (0, -1)
     for d in topdirs:
-        topidx += 1
-        dirvec[0][d] = (topidx, -1)
         dirvec.append({})
+        dirvec[0][d] = (len(dirvec)-1, -1)
+        dirvec[-1][".."] = (0, -1)
 
     # Walk the doc list and update the directory tree according to the
     # url (create intermediary directories if needed, create leaf
@@ -89,17 +97,11 @@
                 if idx != len(path) -1:
                     # This is an intermediate element. Create a
                     # Doc-less directory
-                    topidx += 1
-                    dirvec.append({})
-                    dirvec[fathidx][elt] = (topidx, -1)
-                    fathidx = topidx
+                    fathidx = _createdir(dirvec, fathidx, -1, elt)
                 else:
                     # Last element. If directory, needs a dirvec entry
                     if doc.mtype == 'inode/directory':
-                        topidx += 1
-                        dirvec.append({})
-                        dirvec[fathidx][elt] = (topidx, docidx)
-                        fathidx = topidx
+                        fathidx = _createdir(dirvec, fathidx, docidx, elt)
                     else:
                         dirvec[fathidx][elt] = (-1, docidx)
 
@@ -176,35 +178,42 @@
     return int(a1) - int(a2)
 
 
+def _objidtodiridx(pid):
+    if not pid.startswith(g_myprefix):
+        raise Exception("folders.browse: bad pid %s" % pid)
+
+    if len(g_alldocs) == 0:
+        raise Exception("folders:browse: no docs")
+
+    diridx = pid[len(g_myprefix):]
+    if not diridx:
+        diridx = 0
+    else:
+        if diridx[1] != 'd':
+            raise Exception("folders:browse: called on non dir objid %s" % pid)
+        diridx = int(diridx[2:])
+    
+    if diridx >= len(g_dirvec):
+        raise Exception("folders:browse: bad pid %s" % pid)
+
+    return diridx
+
+
 # Browse method
 # objid is like folders$index
 # flag is meta or children. 
 def browse(pid, flag, httphp, pathprefix):
-    global g_alldocs, g_dirvec
-
-    if not pid.startswith(g_myprefix):
-        uplog("folders.browse: bad pid %s" % pid)
-        return []
-
-    if len(g_alldocs) == 0:
-        uplog("folders:browse: no docs")
-        return []
-
-    diridx = pid[len(g_myprefix):]
-    if not diridx:
-        diridx = 0
-    else:
-        diridx = int(diridx[2:])
-    
-    if diridx >= len(g_dirvec):
-        uplog("folders:browse: bad pid %s" % pid)
-        return []
+
+    diridx = _objidtodiridx(pid)
 
     entries = []
 
     # The basename call is just for diridx==0 (topdirs). Remove it if
     # this proves a performance issue
     for nm,ids in g_dirvec[diridx].iteritems():
+        #uplog("folders:browse: got nm %s" % nm.decode('utf-8'))
+        if nm == "..":
+            continue
         thisdiridx = ids[0]
         thisdocidx = ids[1]
         if thisdiridx >= 0:
@@ -221,5 +230,29 @@
             if e:
                 entries.append(e)
 
-    #return entries
     return sorted(entries, cmp=_cmpentries)
+
+# return path for objid, which has to be a container. This is good old pwd
+def dirpath(objid):
+
+    diridx = _objidtodiridx(objid)
+
+    lpath = []
+    while True:
+        fathidx = g_dirvec[diridx][".."][0]
+        for nm, ids in g_dirvec[fathidx].iteritems():
+            if ids[0] == diridx:
+                lpath.append(nm)
+                break
+        diridx = fathidx
+        if diridx == 0:
+            break
+
+    if not lpath:
+        path = "/"
+    else:
+        path = ""
+    for elt in reversed(lpath):
+        path += elt + "/"
+
+    return path