Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions skyvern/forge/sdk/api/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from skyvern.forge.sdk.api.aws import AsyncAWSClient, aws_client
from skyvern.utils.url_validators import encode_url

_ALLOWED_FILENAME_CHARS = set("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.% ")

_created_folders = set()

LOG = structlog.get_logger()


Expand Down Expand Up @@ -239,7 +243,7 @@ def get_number_of_files_in_directory(directory: Path, recursive: bool = False) -


def sanitize_filename(filename: str) -> str:
return "".join(c for c in filename if c.isalnum() or c in ["-", "_", ".", "%", " "])
return "".join([c for c in filename if c in _ALLOWED_FILENAME_CHARS])


def rename_file(file_path: str, new_file_name: str) -> str:
Expand All @@ -263,8 +267,10 @@ def calculate_sha256_for_file(file_path: str) -> str:


def create_folder_if_not_exist(dir: str) -> None:
path = Path(dir)
path.mkdir(parents=True, exist_ok=True)
if dir not in _created_folders:
path = Path(dir)
path.mkdir(parents=True, exist_ok=True)
_created_folders.add(dir)


def get_skyvern_temp_dir() -> str:
Expand Down