FileSystemDriver does not return all parent folders on startup.

Oct 15, 2015 at 1:41 PM
Edited Oct 15, 2015 at 3:22 PM
At present, the Init method returns cwd files and folders, the parent folder and the root folders on startup. If the depth is greater than 1, then the Parents method fills in the remainder of the tree view.

If I have a tree like this, where /dir111 is the cwd:
/root1
   /dir1
      /dir11
         /dir111            
      /dir12
         /dir121
   /dir2
      /dir22
         /dir23
            /dir231
then FileSystemDriver Init returns:
/root1
   /dir1
      /dir11
         /dir111            
   /dir2
so /dir2 is returned correctly, but /dir12 is missing.

I believe Init should return the root folder and the cwd files and folders, and Parents should return the parent folders up to the root folder.

As an experiment...

I commented lines 184 to 195 of the FileSystemDriver Init method so that it returned only the cwd files and folders and the root folder:
//foreach (Root item in _roots)
//{
//    answer.Files.Add(DTOBase.Create(item.Directory, item));
//}
//if (fullPath.Root.Directory.FullName != fullPath.Directory.FullName)
//{
//    foreach (DirectoryInfo item in fullPath.Root.Directory.GetDirectories())
//    {
//        if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
//            answer.Files.Add(DTOBase.Create(item, fullPath.Root));
//    }
//}
And I rewrote the code in the FileSystemDriver Parents method (213 to 237) as follows:
JsonResult IDriver.Parents(string target)
{

    FullPath fullPath = ParsePath(target);
    TreeResponse answer = new TreeResponse();

    if (fullPath.Directory.FullName == fullPath.Root.Directory.FullName)
    {
        answer.Tree.Add(DTOBase.Create(fullPath.Directory, fullPath.Root));
    }
    else
    {
        DirectoryInfo parent = fullPath.Directory;
        DirectoryInfo root = fullPath.Root.Directory;
             
        answer.Tree.Add(DTOBase.Create(root, fullPath.Root));

        while (parent.FullName != fullPath.Root.Directory.FullName)
        {
            parent = parent.Parent;
                    
            foreach (var item in parent.GetDirectories())
            {
                if ((item.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    answer.Tree.Add(DTOBase.Create(item, fullPath.Root));
                }
            }
        }
    }
    return Json(answer);
}
I now get the required parent folders (including siblings) on startup.

Question: is this the best approach, or have I misunderstood the elfinder spec?