Compare commits

...

1 Commits

Author SHA1 Message Date
Dmitriy Kovalenko c4a55070e2 fix: Make directory change file walking non-blocking 2025-12-10 16:33:28 -08:00
2 changed files with 20 additions and 8 deletions
Generated
+3 -3
View File
@@ -64,11 +64,11 @@
]
},
"locked": {
"lastModified": 1756866691,
"narHash": "sha256-YWJsM0HfdFLcaoP5OeyzjX6MjGnJ0Acm+bg1QN8MKjo=",
"lastModified": 1765334520,
"narHash": "sha256-jTof2+ir9UPmv4lWksYO6WbaXCC0nsDExrB9KZj7Dz4=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "fb6dab6f320291a8edd31c1d67f078c6f7384a02",
"rev": "db61f666aea93b28f644861fbddd37f235cc5983",
"type": "github"
},
"original": {
+17 -5
View File
@@ -3,7 +3,7 @@ use crate::file_picker::FilePicker;
use crate::frecency::FrecencyTracker;
use mlua::prelude::*;
use once_cell::sync::Lazy;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::sync::RwLock;
use std::time::Duration;
@@ -52,7 +52,7 @@ pub fn init_file_picker(_: &Lua, base_path: String) -> LuaResult<bool> {
Ok(true)
}
fn reinit_file_picker_internal(path: std::path::PathBuf) -> Result<(), Error> {
fn reinit_file_picker_internal(path: &Path) -> Result<(), Error> {
let mut file_picker = FILE_PICKER.write().map_err(|_| Error::AcquireItemLock)?;
// drop should clean it anyway but just to be extra sure
@@ -66,7 +66,7 @@ fn reinit_file_picker_internal(path: std::path::PathBuf) -> Result<(), Error> {
Ok(())
}
pub fn restart_index_in_path(_: &Lua, new_path: String) -> LuaResult<bool> {
pub fn restart_index_in_path(_: &Lua, new_path: String) -> LuaResult<()> {
let path = std::path::PathBuf::from(&new_path);
if !path.exists() {
return Err(LuaError::RuntimeError(format!(
@@ -79,8 +79,20 @@ pub fn restart_index_in_path(_: &Lua, new_path: String) -> LuaResult<bool> {
LuaError::RuntimeError(format!("Failed to canonicalize path '{}': {}", new_path, e))
})?;
reinit_file_picker_internal(canonical_path)?;
Ok(true)
// Spawn a background thread to avoid blocking Lua/UI thread
std::thread::spawn(move || {
if let Err(e) = reinit_file_picker_internal(&canonical_path) {
::tracing::error!(
?e,
?canonical_path,
"Failed to index directory after changing"
);
} else {
::tracing::info!(?canonical_path, "Successfully reindexed directory");
}
});
Ok(())
}
pub fn scan_files(_: &Lua, _: ()) -> LuaResult<()> {