Skip to content

Commit

Permalink
verify if work_dir is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Mar 16, 2024
1 parent b266260 commit 4839946
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
11 changes: 11 additions & 0 deletions crates/core/src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env::current_dir;
use std::path::Path;
use std::sync::mpsc::{self, Sender};
use std::sync::Arc;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/devbox.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -46,6 +50,13 @@ impl Devbox {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/devenv.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -46,6 +50,13 @@ impl Devenv {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/flox.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -46,6 +50,13 @@ impl Flox {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/nix.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -46,6 +50,13 @@ impl Nix {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/pipeline.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -156,6 +160,13 @@ impl Pipeline {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down
13 changes: 12 additions & 1 deletion crates/graphql/src/schema/objects/pkgx.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -46,6 +50,13 @@ impl Pkgx {
let graph = ctx.data::<Arc<Mutex<Graph>>>().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() {
Expand Down

0 comments on commit 4839946

Please sign in to comment.