Skip to content

Commit

Permalink
- sanitized characters in path
Browse files Browse the repository at this point in the history
  • Loading branch information
agallardol committed Nov 21, 2024
1 parent 2b73246 commit aa599d4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 10 additions & 4 deletions libs/shinkai-tools-runner/src/tools/deno_execution_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{
path::{self, PathBuf},
};

use super::execution_context::ExecutionContext;
use super::path_buf_ext::PathBufExt;
use super::{execution_context::ExecutionContext, file_name_utils::sanitize_for_file_name};
use nanoid::nanoid;

#[derive(Default, Clone)]
Expand All @@ -26,14 +26,20 @@ pub struct DenoExecutionStorage {
impl DenoExecutionStorage {
pub fn new(context: ExecutionContext) -> Self {
let code_id = format!("{}-{}", context.code_id, nanoid!());
let root =
path::absolute(context.storage.join(context.context_id.clone()).clone()).unwrap();
let root = path::absolute(
context
.storage
.join(sanitize_for_file_name(context.context_id.clone()))
.clone(),
)
.unwrap();
let root_code = path::absolute(root.join("code")).unwrap();
let code = path::absolute(root_code.join(code_id.clone())).unwrap();
let logs = path::absolute(root.join("logs")).unwrap();
let log_file = path::absolute(logs.join(format!(
"log_{}_{}.log",
context.context_id, context.execution_id,
sanitize_for_file_name(context.context_id.clone()),
sanitize_for_file_name(context.execution_id.clone())
)))
.unwrap();
let deno_cache = path::absolute(root.join("deno-cache")).unwrap();
Expand Down
4 changes: 4 additions & 0 deletions libs/shinkai-tools-runner/src/tools/file_name_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

pub fn sanitize_for_file_name(file_name: String) -> String {
file_name.replace(|c: char| !c.is_alphanumeric() && c != '-' && c != '_', "")
}
3 changes: 2 additions & 1 deletion libs/shinkai-tools-runner/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod execution_error;
pub mod run_result;
pub mod tool;
pub mod tool_definition;
mod path_buf_ext;
mod path_buf_ext;
mod file_name_utils;

0 comments on commit aa599d4

Please sign in to comment.