diff --git a/zed/src/fs.rs b/zed/src/fs.rs index 034e06d7c96d4650c76d2f7f3e98f76f9ef4924c..e9d6d9230be0619577a57d4af2bae225b4d44927 100644 --- a/zed/src/fs.rs +++ b/zed/src/fs.rs @@ -31,8 +31,9 @@ pub trait Fs: Send + Sync { fn is_fake(&self) -> bool; } +#[derive(Clone, Debug)] pub struct Metadata { - pub ino: u64, + pub inode: u64, pub mtime: SystemTime, pub is_symlink: bool, pub is_dir: bool, @@ -89,7 +90,7 @@ impl Fs for RealFs { symlink_metadata }; Ok(Some(Metadata { - ino: metadata.ino(), + inode: metadata.ino(), mtime: metadata.modified().unwrap(), is_symlink, is_dir: metadata.file_type().is_dir(), @@ -128,10 +129,7 @@ impl Fs for RealFs { #[derive(Clone, Debug)] struct FakeFsEntry { - inode: u64, - mtime: SystemTime, - is_dir: bool, - is_symlink: bool, + metadata: Metadata, content: Option, } @@ -149,7 +147,7 @@ impl FakeFsState { && path .parent() .and_then(|path| self.entries.get(path)) - .map_or(false, |e| e.is_dir) + .map_or(false, |e| e.metadata.is_dir) { Ok(()) } else { @@ -185,10 +183,12 @@ impl FakeFs { entries.insert( Path::new("/").to_path_buf(), FakeFsEntry { - inode: 0, - mtime: SystemTime::now(), - is_dir: true, - is_symlink: false, + metadata: Metadata { + inode: 0, + mtime: SystemTime::now(), + is_dir: true, + is_symlink: false, + }, content: None, }, ); @@ -211,10 +211,12 @@ impl FakeFs { state.entries.insert( path.to_path_buf(), FakeFsEntry { - inode, - mtime: SystemTime::now(), - is_dir: true, - is_symlink: false, + metadata: Metadata { + inode, + mtime: SystemTime::now(), + is_dir: true, + is_symlink: false, + }, content: None, }, ); @@ -232,10 +234,12 @@ impl FakeFs { state.entries.insert( path.to_path_buf(), FakeFsEntry { - inode, - mtime: SystemTime::now(), - is_dir: false, - is_symlink: false, + metadata: Metadata { + inode, + mtime: SystemTime::now(), + is_dir: false, + is_symlink: false, + }, content: Some(content), }, ); @@ -331,11 +335,11 @@ impl Fs for FakeFs { let mut state = self.state.lock().await; state.validate_path(path)?; if let Some(entry) = state.entries.get_mut(path) { - if entry.is_dir { + if entry.metadata.is_dir { Err(anyhow!("cannot overwrite a directory with a file")) } else { entry.content = Some(text.chunks().collect()); - entry.mtime = SystemTime::now(); + entry.metadata.mtime = SystemTime::now(); state.emit_event(&[path]).await; Ok(()) } @@ -343,10 +347,12 @@ impl Fs for FakeFs { let inode = state.next_inode; state.next_inode += 1; let entry = FakeFsEntry { - inode, - mtime: SystemTime::now(), - is_dir: false, - is_symlink: false, + metadata: Metadata { + inode, + mtime: SystemTime::now(), + is_dir: false, + is_symlink: false, + }, content: Some(text.chunks().collect()), }; state.entries.insert(path.to_path_buf(), entry); @@ -361,17 +367,15 @@ impl Fs for FakeFs { async fn is_file(&self, path: &Path) -> bool { let state = self.state.lock().await; - state.entries.get(path).map_or(false, |entry| !entry.is_dir) + state + .entries + .get(path) + .map_or(false, |entry| !entry.metadata.is_dir) } async fn metadata(&self, path: &Path) -> Result> { let state = self.state.lock().await; - Ok(state.entries.get(path).map(|entry| Metadata { - ino: entry.inode, - mtime: entry.mtime, - is_dir: entry.is_dir, - is_symlink: entry.is_symlink, - })) + Ok(state.entries.get(path).map(|entry| entry.metadata.clone())) } async fn read_dir( diff --git a/zed/src/worktree.rs b/zed/src/worktree.rs index ada7af0c18e1386faad8cd02d8ce8f08d3ecd404..292f6eb9198d7cfad343c7764e40acd16d74a879 100644 --- a/zed/src/worktree.rs +++ b/zed/src/worktree.rs @@ -621,7 +621,7 @@ impl LocalWorktree { EntryKind::File(char_bag_for_path(root_char_bag, &path)) }, path: Arc::from(path), - inode: metadata.ino, + inode: metadata.inode, mtime: metadata.mtime, is_symlink: metadata.is_symlink, is_ignored: false, @@ -1585,7 +1585,7 @@ impl Entry { EntryKind::File(char_bag_for_path(root_char_bag, &path)) }, path, - inode: metadata.ino, + inode: metadata.inode, mtime: metadata.mtime, is_symlink: metadata.is_symlink, is_ignored: false,