Skip to main content

turbo_tasks_fs/
virtual_fs.rs

1use anyhow::{Result, bail};
2use turbo_rcstr::{RcStr, rcstr};
3use turbo_tasks::{ValueToString, Vc};
4
5use crate::{
6    FileContent, FileMeta, FileSystem, FileSystemPath, LinkContent, RawDirectoryContent,
7    WriteLinkContent,
8};
9
10#[derive(ValueToString)]
11#[value_to_string(self.name)]
12#[turbo_tasks::value]
13pub struct VirtualFileSystem {
14    pub name: RcStr,
15}
16
17impl VirtualFileSystem {
18    /// Creates a new [`Vc<VirtualFileSystem>`].
19    ///
20    /// NOTE: This function is not a `turbo_tasks::function` to avoid instances
21    /// being equivalent identity-wise. This ensures that a
22    /// [`FileSystemPath`] created from this [`Vc<VirtualFileSystem>`]
23    /// will never be equivalent, nor be interoperable, with a
24    /// [`FileSystemPath`] created from another
25    /// [`Vc<VirtualFileSystem>`].
26    pub fn new() -> Vc<Self> {
27        Self::cell(VirtualFileSystem {
28            name: rcstr!("virtual file system"),
29        })
30    }
31
32    /// Creates a new [`Vc<VirtualFileSystem>`] with a name.
33    ///
34    /// NOTE: This function is not a `turbo_tasks::function` to avoid instances
35    /// being equivalent identity-wise. This ensures that a
36    /// [`FileSystemPath`] created from this [`Vc<VirtualFileSystem>`]
37    /// will never be equivalent, nor be interoperable, with a
38    /// [`FileSystemPath`] created from another
39    /// [`Vc<VirtualFileSystem>`].
40    pub fn new_with_name(name: RcStr) -> Vc<Self> {
41        Self::cell(VirtualFileSystem { name })
42    }
43}
44
45#[turbo_tasks::value_impl]
46impl FileSystem for VirtualFileSystem {
47    #[turbo_tasks::function]
48    fn read(&self, _fs_path: FileSystemPath) -> Result<Vc<FileContent>> {
49        bail!("Reading is not possible on the virtual file system")
50    }
51
52    #[turbo_tasks::function]
53    fn read_link(&self, _fs_path: FileSystemPath) -> Result<Vc<LinkContent>> {
54        bail!("Reading is not possible on the virtual file system")
55    }
56
57    #[turbo_tasks::function]
58    fn is_junction_point(&self, _fs_path: FileSystemPath) -> Result<Vc<bool>> {
59        bail!("Reading is not possible on the virtual file system")
60    }
61
62    #[turbo_tasks::function]
63    fn raw_read_dir(&self, _fs_path: FileSystemPath) -> Result<Vc<RawDirectoryContent>> {
64        bail!("Reading is not possible on the virtual file system")
65    }
66
67    #[turbo_tasks::function]
68    fn write(&self, _fs_path: FileSystemPath, _content: Vc<FileContent>) -> Result<Vc<()>> {
69        bail!("Writing is not possible on the virtual file system")
70    }
71
72    #[turbo_tasks::function]
73    fn write_link(
74        &self,
75        _fs_path: FileSystemPath,
76        _target: Vc<WriteLinkContent>,
77    ) -> Result<Vc<()>> {
78        bail!("Writing is not possible on the virtual file system")
79    }
80
81    #[turbo_tasks::function]
82    fn metadata(&self, _fs_path: FileSystemPath) -> Result<Vc<FileMeta>> {
83        bail!("Reading is not possible on the virtual file system")
84    }
85}