(folder, prefix string, levels int, dirsOnly bool)
| 2747 | } |
| 2748 | |
| 2749 | func (m *model) GlobalDirectoryTree(folder, prefix string, levels int, dirsOnly bool) ([]*TreeEntry, error) { |
| 2750 | m.mut.RLock() |
| 2751 | _, ok := m.folderCfgs[folder] |
| 2752 | m.mut.RUnlock() |
| 2753 | if !ok { |
| 2754 | return nil, ErrFolderMissing |
| 2755 | } |
| 2756 | |
| 2757 | root := &TreeEntry{ |
| 2758 | Children: make([]*TreeEntry, 0), |
| 2759 | } |
| 2760 | sep := string(filepath.Separator) |
| 2761 | prefix = osutil.NativeFilename(prefix) |
| 2762 | |
| 2763 | if prefix != "" && !strings.HasSuffix(prefix, sep) { |
| 2764 | prefix += sep |
| 2765 | } |
| 2766 | |
| 2767 | for f, err := range itererr.Zip(m.sdb.AllGlobalFilesPrefix(folder, prefix)) { |
| 2768 | if err != nil { |
| 2769 | return nil, err |
| 2770 | } |
| 2771 | |
| 2772 | // Don't include the prefix itself. |
| 2773 | if f.IsInvalid() || f.Deleted || strings.HasPrefix(prefix, f.Name) { |
| 2774 | continue |
| 2775 | } |
| 2776 | |
| 2777 | f.Name = strings.Replace(f.Name, prefix, "", 1) |
| 2778 | |
| 2779 | dir := filepath.Dir(f.Name) |
| 2780 | base := filepath.Base(f.Name) |
| 2781 | |
| 2782 | if levels > -1 && strings.Count(f.Name, sep) > levels { |
| 2783 | continue |
| 2784 | } |
| 2785 | |
| 2786 | parent := root |
| 2787 | if dir != "." { |
| 2788 | for _, path := range strings.Split(dir, sep) { |
| 2789 | child := findByName(parent.Children, path) |
| 2790 | if child == nil { |
| 2791 | return nil, fmt.Errorf("could not find child '%s' for path '%s' in parent '%s'", path, f.Name, parent.Name) |
| 2792 | } |
| 2793 | parent = child |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | if dirsOnly && !f.IsDirectory() { |
| 2798 | continue |
| 2799 | } |
| 2800 | |
| 2801 | parent.Children = append(parent.Children, &TreeEntry{ |
| 2802 | Name: base, |
| 2803 | Type: f.Type.String(), |
| 2804 | ModTime: f.ModTime(), |
| 2805 | Size: f.Size, |
| 2806 | }) |
nothing calls this directly
no test coverage detected