@Override
    public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
        if(directory.isRoot()) {
            final AttributedList<Path> list = new AttributedList<>();
            for(RootFolder root : session.roots()) {
                switch(root.getRootFolderType()) {
                    case 0: // My Files
                    case 1: // Common
                        list.add(new Path(directory, PathNormalizer.name(root.getName()), EnumSet.of(Path.Type.directory, Path.Type.volume),
                                attributes.toAttributes(root)));
                        break;
                }
                listener.chunk(directory, list);
            }
            return list;
        }
        else {
            try {
                final AttributedList<Path> children = new AttributedList<>();
                int pageIndex = 0;
                int fileCount = 0;
                FileContents files;
                do {
                    files = new FilesApi(this.session.getClient()).filesGetById(URIEncoder.encode(fileid.getFileId(directory)),
                            pageIndex,
                            chunksize,
                            "Name asc",
                            0, // All
                            true,
                            false,
                            false
                    );
                    for(File f : files.getFiles()) {
                        final PathAttributes attrs = attributes.toAttributes(f);
                        final EnumSet<Path.Type> type = (f.getFlags() & 1) == 1 ?
                                EnumSet.of(Path.Type.directory) :
                                EnumSet.of(Path.Type.file);
                        children.add(new Path(directory, f.getName(), type, attrs));
                    }
                    pageIndex++;
                    fileCount += files.getFiles().size();
                    listener.chunk(directory, children);
                }
                while(fileCount < files.getTotalRowCount());
                return children;
            }
            catch(ApiException e) {
                throw new StoregateExceptionMappingService(fileid).map("Listing directory {0} failed", e, directory);
            }
        }
    }
@Test
    public void testListRoot() throws Exception {
        final StoregateIdProvider nodeid = new StoregateIdProvider(session);
        final Path directory = new Path("/", EnumSet.of(AbstractPath.Type.directory, Path.Type.volume));
        final AttributedList<Path> list = new StoregateListService(session, nodeid).list(
                directory, new DisabledListProgressListener());
        assertNotSame(AttributedList.emptyList(), list);
        assertFalse(list.isEmpty());
        assertEquals(2, list.size());
        assertNotNull(list.find(new SimplePathPredicate(new Path("/Common files", EnumSet.of(Path.Type.directory, Path.Type.volume)))));
        assertNotNull(list.find(new SimplePathPredicate(new Path("/My files", EnumSet.of(Path.Type.directory, Path.Type.volume)))));
        for(Path f : list) {
            assertSame(directory, f.getParent());
            assertFalse(f.getName().contains(String.valueOf(Path.DELIMITER)));
            assertTrue(f.attributes().getModificationDate() > 0);
            assertTrue(f.attributes().getCreationDate() > 0);
            assertNotNull(nodeid.getFileId(new Path(f).withAttributes(PathAttributes.EMPTY)));
            assertEquals(f.attributes(), new StoregateAttributesFinderFeature(session, nodeid).find(f));
        }
    }