From 09095f2abd83319086d655721bfd29700697f97b Mon Sep 17 00:00:00 2001 From: Nugine Date: Sat, 14 Jun 2025 22:59:52 +0800 Subject: [PATCH] fix(ecstore): fs block_in_place --- ecstore/src/disk/fs.rs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/ecstore/src/disk/fs.rs b/ecstore/src/disk/fs.rs index 79378eec..07475e07 100644 --- a/ecstore/src/disk/fs.rs +++ b/ecstore/src/disk/fs.rs @@ -109,7 +109,7 @@ pub async fn access(path: impl AsRef) -> io::Result<()> { } pub fn access_std(path: impl AsRef) -> io::Result<()> { - std::fs::metadata(path)?; + tokio::task::block_in_place(|| std::fs::metadata(path))?; Ok(()) } @@ -118,7 +118,7 @@ pub async fn lstat(path: impl AsRef) -> io::Result { } pub fn lstat_std(path: impl AsRef) -> io::Result { - std::fs::metadata(path) + tokio::task::block_in_place(|| std::fs::metadata(path)) } pub async fn make_dir_all(path: impl AsRef) -> io::Result<()> { @@ -146,21 +146,27 @@ pub async fn remove_all(path: impl AsRef) -> io::Result<()> { #[tracing::instrument(level = "debug", skip_all)] pub fn remove_std(path: impl AsRef) -> io::Result<()> { - let meta = std::fs::metadata(path.as_ref())?; - if meta.is_dir() { - std::fs::remove_dir(path.as_ref()) - } else { - std::fs::remove_file(path.as_ref()) - } + let path = path.as_ref(); + tokio::task::block_in_place(|| { + let meta = std::fs::metadata(path)?; + if meta.is_dir() { + std::fs::remove_dir(path) + } else { + std::fs::remove_file(path) + } + }) } pub fn remove_all_std(path: impl AsRef) -> io::Result<()> { - let meta = std::fs::metadata(path.as_ref())?; - if meta.is_dir() { - std::fs::remove_dir_all(path.as_ref()) - } else { - std::fs::remove_file(path.as_ref()) - } + let path = path.as_ref(); + tokio::task::block_in_place(|| { + let meta = std::fs::metadata(path)?; + if meta.is_dir() { + std::fs::remove_dir_all(path) + } else { + std::fs::remove_file(path) + } + }) } pub async fn mkdir(path: impl AsRef) -> io::Result<()> { @@ -172,7 +178,7 @@ pub async fn rename(from: impl AsRef, to: impl AsRef) -> io::Result< } pub fn rename_std(from: impl AsRef, to: impl AsRef) -> io::Result<()> { - std::fs::rename(from, to) + tokio::task::block_in_place(|| std::fs::rename(from, to)) } #[tracing::instrument(level = "debug", skip_all)]