pub(crate) async fn list_virtual_entries(
        &self,
        virtual_directory: VirtualDirectory,
        parent_inode: u64,
    ) -> Result<Vec<(u64, FileType, String)>> {
        match virtual_directory {
            VirtualDirectory::InMemory(v) => {
                // These are all other virtual directories.
                let mut entries = vec![
                    (parent_inode, FileType::Directory, ".".to_string()),
                    (parent_inode, FileType::Directory, "..".to_string()),
                ];

                entries.reserve(v.len());
                for dir_name in v.into_iter() {
                    let inode = self.get_virtual_inode(parent_inode, &dir_name).await;
                    entries.push((inode, FileType::Directory, dir_name));
                }

                Ok(entries)
            }
            VirtualDirectory::Query { query } => self.list_entries(query, parent_inode).await,
            VirtualDirectory::Mount { contents } => match contents {
                Contents::Root { root } => {
                    let mut entries = vec![
                        (parent_inode, FileType::Directory, ".".to_string()),
                        (parent_inode, FileType::Directory, "..".to_string()),
                    ];
                    let item_inode = self.get_inode(&root).await;
                    let meta = self
                        .client
                        .get_meta(&root)
                        .await?
                        .ok_or_else(|| anyhow!("mount meta does not exist"))?;
                    self.name_to_blobid
                        .insert((parent_inode, meta.name.clone()), root)
                        .await;
                    let t = if meta.blob_type == Type::File {
                        FileType::RegularFile
                    } else {
                        FileType::Directory
                    };
                    entries.push((item_inode, t, meta.name));

                    Ok(entries)
                }
                Contents::Virtual(mounts) => {
                    let mut entries = vec![
                        (parent_inode, FileType::Directory, ".".to_string()),
                        (parent_inode, FileType::Directory, "..".to_string()),
                    ];

                    // Create a virtual directory for each of our mounts.
                    for (k, contents) in mounts.into_iter() {
                        let mount_inode = self.get_virtual_inode(parent_inode, &k).await;

                        self.virtual_directories_inodes
                            .insert(mount_inode, VirtualDirectory::Mount { contents })
                            .await;
                        entries.push((mount_inode, FileType::Directory, k));
                    }

                    Ok(entries)
                }
                Contents::Query {
                    expression,
                    group_by_meta_keys,
                    group_by_tags,
                } => {
                    let root_query = Query::default().with_expression(expression)?;

                    let should_group = group_by_tags || !group_by_meta_keys.is_empty();

                    if should_group {
                        let mut entries = vec![
                            (parent_inode, FileType::Directory, ".".to_string()),
                            (parent_inode, FileType::Directory, "..".to_string()),
                        ];
                        self.populate_virtual_directories(root_query, parent_inode)
                            .await?;

                        // TODO: Will need to use a more unique inode name since we can nest.
                        let tags_inode = self.get_virtual_inode(parent_inode, "tags").await;
                        entries.push((tags_inode, FileType::Directory, "tags".to_string()));

                        for group_key in group_by_meta_keys.iter() {
                            let kv_inode = self.get_virtual_inode(parent_inode, group_key).await;
                            entries.push((kv_inode, FileType::Directory, group_key.clone()));
                        }

                        Ok(entries)
                    } else {
                        // Display the results as a flat list.
                        self.list_entries(root_query, parent_inode).await
                    }
                }
            },
        }
    }
/// Lists entries for a virtual (created on the client by a query) directory.
Lists entries for a virtual (created on the client by a query) directory.
Lists entries for a virtual ( created on the client by a query ) directory .
pub(crate) async fn list_virtual_entries(
        &self,
        virtual_directory: VirtualDirectory,
        parent_inode: u64,
    ) -> Result<Vec<(u64, FileType, String)>> {
        match virtual_directory {
            VirtualDirectory::InMemory(v) => {
                // These are all other virtual directories.
                let mut entries = vec![
                    (parent_inode, FileType::Directory, ".".to_string()),
                    (parent_inode, FileType::Directory, "..".to_string()),
                ];
                entries.reserve(v.len());
                for dir_name in v.into_iter() {
                    let inode = self.get_virtual_inode(parent_inode, &dir_name).await;
                    entries.push((inode, FileType::Directory, dir_name));
                }
                Ok(entries)
            }
            VirtualDirectory::Query { query } => self.list_entries(query, parent_inode).await,
            VirtualDirectory::Mount { contents } => match contents {
                Contents::Root { root } => {
                    let mut entries = vec![
                        (parent_inode, FileType::Directory, ".".to_string()),
                        (parent_inode, FileType::Directory, "..".to_string()),
                    ];
                    let item_inode = self.get_inode(&root).await;
                    let meta = self
                        .client
                        .get_meta(&root)
                        .await?
                        .ok_or_else(|| anyhow!("mount meta does not exist"))?;
                    self.name_to_blobid
                        .insert((parent_inode, meta.name.clone()), root)
                        .await;
                    let t = if meta.blob_type == Type::File {
                        FileType::RegularFile
                    } else {
                        FileType::Directory
                    };
                    entries.push((item_inode, t, meta.name));
                    Ok(entries)
                }
                Contents::Virtual(mounts) => {
                    let mut entries = vec![
                        (parent_inode, FileType::Directory, ".".to_string()),
                        (parent_inode, FileType::Directory, "..".to_string()),
                    ];
                    // Create a virtual directory for each of our mounts.
                    for (k, contents) in mounts.into_iter() {
                        let mount_inode = self.get_virtual_inode(parent_inode, &k).await;
                        self.virtual_directories_inodes
                            .insert(mount_inode, VirtualDirectory::Mount { contents })
                            .await;
                        entries.push((mount_inode, FileType::Directory, k));
                    }
                    Ok(entries)
                }
                Contents::Query {
                    expression,
                    group_by_meta_keys,
                    group_by_tags,
                } => {
                    let root_query = Query::default().with_expression(expression)?;
                    let should_group = group_by_tags || !group_by_meta_keys.is_empty();
                    if should_group {
                        let mut entries = vec![
                            (parent_inode, FileType::Directory, ".".to_string()),
                            (parent_inode, FileType::Directory, "..".to_string()),
                        ];
                        self.populate_virtual_directories(root_query, parent_inode)
                            .await?;
                        // TODO: Will need to use a more unique inode name since we can nest.
                        let tags_inode = self.get_virtual_inode(parent_inode, "tags").await;
                        entries.push((tags_inode, FileType::Directory, "tags".to_string()));
                        for group_key in group_by_meta_keys.iter() {
                            let kv_inode = self.get_virtual_inode(parent_inode, group_key).await;
                            entries.push((kv_inode, FileType::Directory, group_key.clone()));
                        }
                        Ok(entries)
                    } else {
                        // Display the results as a flat list.
                        self.list_entries(root_query, parent_inode).await
                    }
                }
            },
        }
    }
pub ( crate ) async fn list_virtual_entries ( & self , virtual_directory : VirtualDirectory , parent_inode : u64 , ) -> Result < Vec < ( u64 , FileType , String ) > > { match virtual_directory { VirtualDirectory :: InMemory ( v ) => { // These are all other virtual directories. let mut entries = vec ! [ ( parent_inode FileType Directory " " to_string ( ) ) ( parent_inode FileType Directory " " to_string ( ) ) ] ; entries . reserve ( v . len ( ) ) ; for dir_name in v . into_iter ( ) { let inode = self . get_virtual_inode ( parent_inode , & dir_name ) . await ; entries . push ( ( inode , FileType :: Directory , dir_name ) ) ; } Ok ( entries ) } VirtualDirectory :: Query { query } => self . list_entries ( query , parent_inode ) . await , VirtualDirectory :: Mount { contents } => match contents { Contents :: Root { root } => { let mut entries = vec ! [ ( parent_inode FileType Directory " " to_string ( ) ) ( parent_inode FileType Directory " " to_string ( ) ) ] ; let item_inode = self . get_inode ( & root ) . await ; let meta = self . client . get_meta ( & root ) . await ? . ok_or_else ( | | anyhow ! ( " " ) ) ? ; self . name_to_blobid . insert ( ( parent_inode , meta . name . clone ( ) ) , root ) . await ; let t = if meta . blob_type == Type :: File { FileType :: RegularFile } else { FileType :: Directory } ; entries . push ( ( item_inode , t , meta . name ) ) ; Ok ( entries ) } Contents :: Virtual ( mounts ) => { let mut entries = vec ! [ ( parent_inode FileType Directory " " to_string ( ) ) ( parent_inode FileType Directory " " to_string ( ) ) ] ; // Create a virtual directory for each of our mounts. for ( k , contents ) in mounts . into_iter ( ) { let mount_inode = self . get_virtual_inode ( parent_inode , & k ) . await ; self . virtual_directories_inodes . insert ( mount_inode , VirtualDirectory :: Mount { contents } ) . await ; entries . push ( ( mount_inode , FileType :: Directory , k ) ) ; } Ok ( entries ) } Contents :: Query { expression , group_by_meta_keys , group_by_tags , } => { let root_query = Query :: default ( ) . with_expression ( expression ) ? ; let should_group = group_by_tags || ! group_by_meta_keys . is_empty ( ) ; if should_group { let mut entries = vec ! [ ( parent_inode FileType Directory " " to_string ( ) ) ( parent_inode FileType Directory " " to_string ( ) ) ] ; self . populate_virtual_directories ( root_query , parent_inode ) . await ? ; // TODO: Will need to use a more unique inode name since we can nest. let tags_inode = self . get_virtual_inode ( parent_inode , " " ) . await ; entries . push ( ( tags_inode , FileType :: Directory , " " . to_string ( ) ) ) ; for group_key in group_by_meta_keys . iter ( ) { let kv_inode = self . get_virtual_inode ( parent_inode , group_key ) . await ; entries . push ( ( kv_inode , FileType :: Directory , group_key . clone ( ) ) ) ; } Ok ( entries ) } else { // Display the results as a flat list. self . list_entries ( root_query , parent_inode ) . await } } } , } }
Lists entries for a virtual (created on the client by a query) directory.
Lists entries for a virtual ( created on the client by a query ) directory .
&self
virtual_directory
VirtualDirectory
parent_inode
u64
&self
virtual_directory
VirtualDirectory
parent_inode
u64