Fix fifo files hanging the project wide search (#16039)

Release Notes:

- Fixed the issue related to the project wide search being stuck when
project contains .fifo files
- Might potentially solve the following issue
https://github.com/zed-industries/zed/issues/7360
This commit is contained in:
TheCub3 2024-08-26 21:40:20 +05:00 committed by GitHub
parent aaddb73b28
commit 2f08a0a28c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 34 additions and 3 deletions

View File

@ -86,6 +86,7 @@ CREATE TABLE "worktree_entries" (
"is_ignored" BOOL NOT NULL, "is_ignored" BOOL NOT NULL,
"is_deleted" BOOL NOT NULL, "is_deleted" BOOL NOT NULL,
"git_status" INTEGER, "git_status" INTEGER,
"is_fifo" BOOL NOT NULL,
PRIMARY KEY(project_id, worktree_id, id), PRIMARY KEY(project_id, worktree_id, id),
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
); );

View File

@ -0,0 +1,2 @@
ALTER TABLE "worktree_entries"
ADD "is_fifo" BOOL NOT NULL DEFAULT FALSE;

View File

@ -319,6 +319,7 @@ impl Database {
git_status: ActiveValue::set(entry.git_status.map(|status| status as i64)), git_status: ActiveValue::set(entry.git_status.map(|status| status as i64)),
is_deleted: ActiveValue::set(false), is_deleted: ActiveValue::set(false),
scan_id: ActiveValue::set(update.scan_id as i64), scan_id: ActiveValue::set(update.scan_id as i64),
is_fifo: ActiveValue::set(entry.is_fifo),
} }
})) }))
.on_conflict( .on_conflict(
@ -727,6 +728,7 @@ impl Database {
is_ignored: db_entry.is_ignored, is_ignored: db_entry.is_ignored,
is_external: db_entry.is_external, is_external: db_entry.is_external,
git_status: db_entry.git_status.map(|status| status as i32), git_status: db_entry.git_status.map(|status| status as i32),
is_fifo: db_entry.is_fifo,
}); });
} }
} }

View File

@ -663,6 +663,7 @@ impl Database {
is_ignored: db_entry.is_ignored, is_ignored: db_entry.is_ignored,
is_external: db_entry.is_external, is_external: db_entry.is_external,
git_status: db_entry.git_status.map(|status| status as i32), git_status: db_entry.git_status.map(|status| status as i32),
is_fifo: db_entry.is_fifo,
}); });
} }
} }

View File

@ -21,6 +21,7 @@ pub struct Model {
pub is_external: bool, pub is_external: bool,
pub is_deleted: bool, pub is_deleted: bool,
pub scan_id: i64, pub scan_id: i64,
pub is_fifo: bool,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View File

@ -9,6 +9,9 @@ use std::{fs::File, os::fd::AsFd};
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
#[cfg(unix)]
use std::os::unix::fs::FileTypeExt;
use async_tar::Archive; use async_tar::Archive;
use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt}; use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt};
use git::repository::{GitRepository, RealGitRepository}; use git::repository::{GitRepository, RealGitRepository};
@ -149,6 +152,7 @@ pub struct Metadata {
pub mtime: SystemTime, pub mtime: SystemTime,
pub is_symlink: bool, pub is_symlink: bool,
pub is_dir: bool, pub is_dir: bool,
pub is_fifo: bool,
} }
#[derive(Default)] #[derive(Default)]
@ -428,11 +432,18 @@ impl Fs for RealFs {
#[cfg(windows)] #[cfg(windows)]
let inode = file_id(path).await?; let inode = file_id(path).await?;
#[cfg(windows)]
let is_fifo = false;
#[cfg(unix)]
let is_fifo = metadata.file_type().is_fifo();
Ok(Some(Metadata { Ok(Some(Metadata {
inode, inode,
mtime: metadata.modified().unwrap(), mtime: metadata.modified().unwrap(),
is_symlink, is_symlink,
is_dir: metadata.file_type().is_dir(), is_dir: metadata.file_type().is_dir(),
is_fifo,
})) }))
} }
@ -1537,12 +1548,14 @@ impl Fs for FakeFs {
mtime: *mtime, mtime: *mtime,
is_dir: false, is_dir: false,
is_symlink, is_symlink,
is_fifo: false,
}, },
FakeFsEntry::Dir { inode, mtime, .. } => Metadata { FakeFsEntry::Dir { inode, mtime, .. } => Metadata {
inode: *inode, inode: *inode,
mtime: *mtime, mtime: *mtime,
is_dir: true, is_dir: true,
is_symlink, is_symlink,
is_fifo: false,
}, },
FakeFsEntry::Symlink { .. } => unreachable!(), FakeFsEntry::Symlink { .. } => unreachable!(),
})) }))

View File

@ -10969,10 +10969,15 @@ async fn search_snapshots(
abs_path.clear(); abs_path.clear();
abs_path.push(&snapshot.abs_path()); abs_path.push(&snapshot.abs_path());
abs_path.push(&entry.path); abs_path.push(&entry.path);
if let Some(file) = fs.open_sync(&abs_path).await.log_err() {
query.detect(file).unwrap_or(false) if entry.is_fifo {
} else {
false false
} else {
if let Some(file) = fs.open_sync(&abs_path).await.log_err() {
query.detect(file).unwrap_or(false)
} else {
false
}
} }
} else { } else {
false false

View File

@ -1678,6 +1678,7 @@ impl ProjectPanel {
canonical_path: entry.canonical_path.clone(), canonical_path: entry.canonical_path.clone(),
is_symlink: entry.is_symlink, is_symlink: entry.is_symlink,
char_bag: entry.char_bag, char_bag: entry.char_bag,
is_fifo: entry.is_fifo,
}); });
} }
if expanded_dir_ids.binary_search(&entry.id).is_err() if expanded_dir_ids.binary_search(&entry.id).is_err()

View File

@ -1814,6 +1814,7 @@ message Entry {
bool is_ignored = 7; bool is_ignored = 7;
bool is_external = 8; bool is_external = 8;
optional GitStatus git_status = 9; optional GitStatus git_status = 9;
bool is_fifo = 10;
} }
message RepositoryEntry { message RepositoryEntry {

View File

@ -3186,6 +3186,7 @@ pub struct Entry {
/// Whether this entry is considered to be a `.env` file. /// Whether this entry is considered to be a `.env` file.
pub is_private: bool, pub is_private: bool,
pub char_bag: CharBag, pub char_bag: CharBag,
pub is_fifo: bool,
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@ -3246,6 +3247,7 @@ impl Entry {
is_private: false, is_private: false,
git_status: None, git_status: None,
char_bag, char_bag,
is_fifo: metadata.is_fifo,
} }
} }
@ -5106,6 +5108,7 @@ impl<'a> From<&'a Entry> for proto::Entry {
is_ignored: entry.is_ignored, is_ignored: entry.is_ignored,
is_external: entry.is_external, is_external: entry.is_external,
git_status: entry.git_status.map(git_status_to_proto), git_status: entry.git_status.map(git_status_to_proto),
is_fifo: entry.is_fifo,
} }
} }
} }
@ -5134,6 +5137,7 @@ impl<'a> TryFrom<(&'a CharBag, proto::Entry)> for Entry {
is_private: false, is_private: false,
is_symlink: entry.is_symlink, is_symlink: entry.is_symlink,
char_bag, char_bag,
is_fifo: entry.is_fifo,
}) })
} }
} }