diff --git a/crates/core/src/deps.rs b/crates/core/src/deps.rs index 43185cf..a9e2ceb 100644 --- a/crates/core/src/deps.rs +++ b/crates/core/src/deps.rs @@ -1,4 +1,5 @@ use std::env::current_dir; +use std::path::Path; use std::sync::mpsc::{self, Sender}; use std::sync::Arc; @@ -73,6 +74,11 @@ impl Graph { let (tx, rx) = mpsc::channel(); if self.vertices[i].label == "withWorkdir" { + if !Path::new(&self.vertices[i].command).exists() { + println!("Error: {}", self.vertices[i].id); + self.tx.send((self.vertices[i].command.clone(), 1)).unwrap(); + break; + } self.work_dir = self.vertices[i].command.clone(); continue; } @@ -123,6 +129,11 @@ impl Graph { let (tx, rx) = mpsc::channel(); if self.vertices[i].label == "withWorkdir" { + if !Path::new(&self.vertices[i].command).exists() { + println!("Error: {}", self.vertices[i].id); + self.tx.send((self.vertices[i].command.clone(), 1)).unwrap(); + break; + } self.work_dir = self.vertices[i].command.clone(); continue; } diff --git a/crates/graphql/src/schema/objects/devbox.rs b/crates/graphql/src/schema/objects/devbox.rs index 9ad7ee3..f0fc420 100644 --- a/crates/graphql/src/schema/objects/devbox.rs +++ b/crates/graphql/src/schema/objects/devbox.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -46,6 +50,13 @@ impl Devbox { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() && !path.starts_with("/") { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() { diff --git a/crates/graphql/src/schema/objects/devenv.rs b/crates/graphql/src/schema/objects/devenv.rs index a60f4b3..6d7c223 100644 --- a/crates/graphql/src/schema/objects/devenv.rs +++ b/crates/graphql/src/schema/objects/devenv.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -46,6 +50,13 @@ impl Devenv { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() && !path.starts_with("/") { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() { diff --git a/crates/graphql/src/schema/objects/flox.rs b/crates/graphql/src/schema/objects/flox.rs index 416aae7..731a546 100644 --- a/crates/graphql/src/schema/objects/flox.rs +++ b/crates/graphql/src/schema/objects/flox.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -46,6 +50,13 @@ impl Flox { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() && !path.starts_with("/") { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() { diff --git a/crates/graphql/src/schema/objects/nix.rs b/crates/graphql/src/schema/objects/nix.rs index dd9e0d0..a379232 100644 --- a/crates/graphql/src/schema/objects/nix.rs +++ b/crates/graphql/src/schema/objects/nix.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -46,6 +50,13 @@ impl Nix { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() && !path.starts_with("/") { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() { diff --git a/crates/graphql/src/schema/objects/pipeline.rs b/crates/graphql/src/schema/objects/pipeline.rs index c7049ef..a898ee1 100644 --- a/crates/graphql/src/schema/objects/pipeline.rs +++ b/crates/graphql/src/schema/objects/pipeline.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -156,6 +160,13 @@ impl Pipeline { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() { diff --git a/crates/graphql/src/schema/objects/pkgx.rs b/crates/graphql/src/schema/objects/pkgx.rs index be413c6..5882d03 100644 --- a/crates/graphql/src/schema/objects/pkgx.rs +++ b/crates/graphql/src/schema/objects/pkgx.rs @@ -1,4 +1,8 @@ -use std::sync::{mpsc::Receiver, Arc, Mutex}; +use std::{ + fs::canonicalize, + path::Path, + sync::{mpsc::Receiver, Arc, Mutex}, +}; use async_graphql::{Context, Error, Object, ID}; use fluentci_core::deps::{Graph, GraphCommand}; @@ -46,6 +50,13 @@ impl Pkgx { let graph = ctx.data::>>().unwrap(); let mut graph = graph.lock().unwrap(); + if !Path::new(&path).exists() && !path.starts_with("/") { + let dir = canonicalize(".").unwrap(); + let dir = dir.to_str().unwrap(); + let dir = format!("{}/{}", dir, path); + return Err(Error::new(format!("Path `{}` does not exist", dir))); + } + let id = Uuid::new_v4().to_string(); let dep_id = graph.vertices[graph.size() - 1].id.clone(); let deps = match graph.size() {