mirror of
https://github.com/pesde-pkg/pesde.git
synced 2025-04-10 22:00:55 +01:00
refactor: switch from sync Path::exists() method
This commit disallows the method through clippy and switches to the async equivalents, as to not block the async runtime.
This commit is contained in:
parent
af93b7d584
commit
b8c4f7486b
5 changed files with 39 additions and 14 deletions
|
@ -1 +1,4 @@
|
||||||
avoid-breaking-exported-api = false
|
avoid-breaking-exported-api = false
|
||||||
|
disallowed-methods = [
|
||||||
|
"std::path::Path::exists"
|
||||||
|
]
|
|
@ -347,7 +347,7 @@ info: otherwise, the file was deemed unnecessary, if you don't understand why, p
|
||||||
|
|
||||||
let build_file_path = project.package_dir().join(build_file);
|
let build_file_path = project.package_dir().join(build_file);
|
||||||
|
|
||||||
if !build_file_path.exists() {
|
if fs::metadata(&build_file_path).await.is_err() {
|
||||||
anyhow::bail!("build file {build_file} does not exist");
|
anyhow::bail!("build file {build_file} does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ info: otherwise, the file was deemed unnecessary, if you don't understand why, p
|
||||||
for relative_path in &paths {
|
for relative_path in &paths {
|
||||||
let path = project.package_dir().join(relative_path);
|
let path = project.package_dir().join(relative_path);
|
||||||
|
|
||||||
if !path.exists() {
|
if fs::metadata(&path).await.is_err() {
|
||||||
anyhow::bail!("included file `{}` does not exist", path.display());
|
anyhow::bail!("included file `{}` does not exist", path.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::cli::{style::WARN_STYLE, up_to_date_lockfile};
|
use crate::cli::{style::WARN_STYLE, up_to_date_lockfile};
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
|
use fs_err::tokio as fs;
|
||||||
use futures::{StreamExt as _, TryStreamExt as _};
|
use futures::{StreamExt as _, TryStreamExt as _};
|
||||||
use pesde::{
|
use pesde::{
|
||||||
errors::{ManifestReadError, WorkspaceMembersError},
|
errors::{ManifestReadError, WorkspaceMembersError},
|
||||||
|
@ -154,7 +155,7 @@ impl RunCommand {
|
||||||
let relative_path = RelativePathBuf::from(package_or_script);
|
let relative_path = RelativePathBuf::from(package_or_script);
|
||||||
let path = relative_path.to_path(project.package_dir());
|
let path = relative_path.to_path(project.package_dir());
|
||||||
|
|
||||||
if !path.exists() {
|
if fs::metadata(&path).await.is_err() {
|
||||||
anyhow::bail!("path `{}` does not exist", path.display());
|
anyhow::bail!("path `{}` does not exist", path.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +195,9 @@ impl RunCommand {
|
||||||
.context("failed to canonicalize parent")?;
|
.context("failed to canonicalize parent")?;
|
||||||
|
|
||||||
if members.contains(&canonical_path)
|
if members.contains(&canonical_path)
|
||||||
&& canonical_path.join(MANIFEST_FILE_NAME).exists()
|
&& fs::metadata(canonical_path.join(MANIFEST_FILE_NAME))
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
{
|
{
|
||||||
break 'finder canonical_path;
|
break 'finder canonical_path;
|
||||||
}
|
}
|
||||||
|
|
38
src/lib.rs
38
src/lib.rs
|
@ -23,6 +23,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
use tokio::io::AsyncReadExt as _;
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
use wax::Pattern as _;
|
use wax::Pattern as _;
|
||||||
|
|
||||||
|
@ -396,9 +397,16 @@ pub async fn find_roots(
|
||||||
let mut workspace_dir = None::<PathBuf>;
|
let mut workspace_dir = None::<PathBuf>;
|
||||||
|
|
||||||
async fn get_workspace_members(
|
async fn get_workspace_members(
|
||||||
|
manifest_file: &mut fs::File,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Result<HashSet<PathBuf>, errors::FindRootsError> {
|
) -> Result<HashSet<PathBuf>, errors::FindRootsError> {
|
||||||
let manifest = deser_manifest(path).await?;
|
let mut manifest = String::new();
|
||||||
|
manifest_file
|
||||||
|
.read_to_string(&mut manifest)
|
||||||
|
.await
|
||||||
|
.map_err(errors::ManifestReadError::Io)?;
|
||||||
|
let manifest: Manifest = toml::from_str(&manifest)
|
||||||
|
.map_err(|e| errors::ManifestReadError::Serde(path.to_path_buf(), e))?;
|
||||||
|
|
||||||
if manifest.workspace_members.is_empty() {
|
if manifest.workspace_members.is_empty() {
|
||||||
return Ok(HashSet::new());
|
return Ok(HashSet::new());
|
||||||
|
@ -417,23 +425,33 @@ pub async fn find_roots(
|
||||||
while let Some(path) = current_path {
|
while let Some(path) = current_path {
|
||||||
current_path = path.parent().map(Path::to_path_buf);
|
current_path = path.parent().map(Path::to_path_buf);
|
||||||
|
|
||||||
if !path.join(MANIFEST_FILE_NAME).exists() {
|
if workspace_dir.is_some() {
|
||||||
continue;
|
if let Some(project_root) = project_root {
|
||||||
|
return Ok((project_root, workspace_dir));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match (project_root.as_ref(), workspace_dir.as_ref()) {
|
let mut manifest = match fs::File::open(path.join(MANIFEST_FILE_NAME)).await {
|
||||||
(Some(project_root), Some(workspace_dir)) => {
|
Ok(manifest) => manifest,
|
||||||
return Ok((project_root.clone(), Some(workspace_dir.clone())));
|
Err(e) if e.kind() == std::io::ErrorKind::NotFound => continue,
|
||||||
}
|
Err(e) => return Err(errors::ManifestReadError::Io(e).into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
match (project_root.as_ref(), workspace_dir.as_ref()) {
|
||||||
(Some(project_root), None) => {
|
(Some(project_root), None) => {
|
||||||
if get_workspace_members(&path).await?.contains(project_root) {
|
if get_workspace_members(&mut manifest, &path)
|
||||||
|
.await?
|
||||||
|
.contains(project_root)
|
||||||
|
{
|
||||||
workspace_dir = Some(path);
|
workspace_dir = Some(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
if get_workspace_members(&path).await?.contains(&cwd) {
|
if get_workspace_members(&mut manifest, &path)
|
||||||
|
.await?
|
||||||
|
.contains(&cwd)
|
||||||
|
{
|
||||||
// initializing a new member of a workspace
|
// initializing a new member of a workspace
|
||||||
return Ok((cwd, Some(path)));
|
return Ok((cwd, Some(path)));
|
||||||
}
|
}
|
||||||
|
@ -441,7 +459,7 @@ pub async fn find_roots(
|
||||||
project_root = Some(path);
|
project_root = Some(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
(None, Some(_)) => unreachable!(),
|
(_, _) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
spawn_blocking(move || {
|
spawn_blocking(move || {
|
||||||
|
#[allow(clippy::disallowed_methods)]
|
||||||
let repo = if dot_git.exists() {
|
let repo = if dot_git.exists() {
|
||||||
let repo = Repository::open(&container_folder)?;
|
let repo = Repository::open(&container_folder)?;
|
||||||
reset_repo(&repo)?;
|
reset_repo(&repo)?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue