このコンテンツはまだ日本語訳がありません。
FileSystem
Main class for a new FileSystem instance.
Constructors
new FileSystem()
def initialize(sandbox_id:, toolbox_api:)Initializes a new FileSystem instance.
Parameters:
sandbox_idString - The Sandbox IDtoolbox_apiDaytonaToolboxApiClient:FileSystemApi - API client for Sandbox operations
Returns:
FileSystem- a new instance of FileSystem
Methods
sandbox_id()
def sandbox_id()Returns:
String- The Sandbox ID
toolbox_api()
def toolbox_api()Returns:
DaytonaToolboxApiClient:FileSystemApi- API client for Sandbox operations
create_folder()
def create_folder(path, mode)Creates a new directory in the Sandbox at the specified path with the given permissions.
Parameters:
pathString - Path where the folder should be created. Relative paths are resolved based on the sandbox working directory.modeString - Folder permissions in octal format (e.g., “755” for rwxr-xr-x).
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Create a directory with standard permissionssandbox.fs.create_folder("workspace/data", "755")
# Create a private directorysandbox.fs.create_folder("workspace/secrets", "700")delete_file()
def delete_file(path, recursive:)Deletes a file from the Sandbox.
Parameters:
pathString - Path to the file to delete. Relative paths are resolved based on the sandbox working directory.recursiveBoolean - If the file is a directory, this must be true to delete it.
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Delete a filesandbox.fs.delete_file("workspace/data/old_file.txt")
# Delete a directory recursivelysandbox.fs.delete_file("workspace/old_dir", recursive: true)get_file_info()
def get_file_info(path)Gets detailed information about a file or directory, including its size, permissions, and timestamps.
Parameters:
pathString - Path to the file or directory. Relative paths are resolved based on the sandbox working directory.
Returns:
DaytonaApiClient:FileInfo- Detailed file information
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Get file metadatainfo = sandbox.fs.get_file_info("workspace/data/file.txt")puts "Size: #{info.size} bytes"puts "Modified: #{info.mod_time}"puts "Mode: #{info.mode}"
# Check if path is a directoryinfo = sandbox.fs.get_file_info("workspace/data")puts "Path is a directory" if info.is_dirlist_files()
def list_files(path)Lists files and directories in a given path and returns their information, similar to the ls -l command.
Parameters:
pathString - Path to the directory to list contents from. Relative paths are resolved based on the sandbox working directory.
Returns:
Array\<DaytonaApiClient:FileInfo\>- List of file and directory information
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# List directory contentsfiles = sandbox.fs.list_files("workspace/data")
# Print files and their sizesfiles.each do |file| puts "#{file.name}: #{file.size} bytes" unless file.is_dirend
# List only directoriesdirs = files.select(&:is_dir)puts "Subdirectories: #{dirs.map(&:name).join(', ')}"download_file()
def download_file(remote_path, local_path)Downloads a file from the Sandbox. Returns the file contents as a string. This method is useful when you want to load the file into memory without saving it to disk. It can only be used for smaller files.
Parameters:
remote_pathString - Path to the file in the Sandbox. Relative paths are resolved based on the sandbox working directory.local_pathString, nil - Optional path to save the file locally. If provided, the file will be saved to disk.
Returns:
File, nil- The file if local_path is nil, otherwise nil
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Download and get file contentcontent = sandbox.fs.download_file("workspace/data/file.txt")puts content
# Download and save a file locallysandbox.fs.download_file("workspace/data/file.txt", "local_copy.txt")size_mb = File.size("local_copy.txt") / 1024.0 / 1024.0puts "Size of the downloaded file: #{size_mb} MB"upload_file()
def upload_file(source, remote_path)Uploads a file to the specified path in the Sandbox. If a file already exists at the destination path, it will be overwritten.
Parameters:
sourceString, IO - File contents as a string/bytes or a local file path or IO object.remote_pathString - Path to the destination file. Relative paths are resolved based on the sandbox working directory.
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Upload a text file from string contentcontent = "Hello, World!"sandbox.fs.upload_file(content, "tmp/hello.txt")
# Upload a local filesandbox.fs.upload_file("local_file.txt", "tmp/file.txt")
# Upload binary datadata = { key: "value" }.to_jsonsandbox.fs.upload_file(data, "tmp/config.json")upload_files()
def upload_files(files)Uploads multiple files to the Sandbox. If files already exist at the destination paths, they will be overwritten.
Parameters:
filesArray<FileUpload> - List of files to upload.
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Upload multiple filesfiles = [ FileUpload.new("Content of file 1", "/tmp/file1.txt"), FileUpload.new("workspace/data/file2.txt", "/tmp/file2.txt"), FileUpload.new('{"key": "value"}', "/tmp/config.json")]sandbox.fs.upload_files(files)find_files()
def find_files(path, pattern)Searches for files containing a pattern, similar to the grep command.
Parameters:
pathString - Path to the file or directory to search. If the path is a directory, the search will be performed recursively. Relative paths are resolved based on the sandbox working directory.patternString - Search pattern to match against file contents.
Returns:
Array\<DaytonaApiClient:Match\>- List of matches found in files
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Search for TODOs in Ruby filesmatches = sandbox.fs.find_files("workspace/src", "TODO:")matches.each do |match| puts "#{match.file}:#{match.line}: #{match.content.strip}"endsearch_files()
def search_files(path, pattern)Searches for files and directories whose names match the specified pattern. The pattern can be a simple string or a glob pattern.
Parameters:
pathString - Path to the root directory to start search from. Relative paths are resolved based on the sandbox working directory.patternString - Pattern to match against file names. Supports glob patterns (e.g., “*.rb” for Ruby files).
Returns:
DaytonaApiClient:SearchFilesResponse
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Find all Ruby filesresult = sandbox.fs.search_files("workspace", "*.rb")result.files.each { |file| puts file }
# Find files with specific prefixresult = sandbox.fs.search_files("workspace/data", "test_*")puts "Found #{result.files.length} test files"move_files()
def move_files(source, destination)Moves or renames a file or directory. The parent directory of the destination must exist.
Parameters:
sourceString - Path to the source file or directory. Relative paths are resolved based on the sandbox working directory.destinationString - Path to the destination. Relative paths are resolved based on the sandbox working directory.
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Rename a filesandbox.fs.move_files( "workspace/data/old_name.txt", "workspace/data/new_name.txt")
# Move a file to a different directorysandbox.fs.move_files( "workspace/data/file.txt", "workspace/archive/file.txt")
# Move a directorysandbox.fs.move_files( "workspace/old_dir", "workspace/new_dir")replace_in_files()
def replace_in_files(files:, pattern:, new_value:)Performs search and replace operations across multiple files.
Parameters:
filesArray<String> - List of file paths to perform replacements in. Relative paths are resolved based on the sandbox working directory.patternString - Pattern to search for.new_valueString - Text to replace matches with.
Returns:
Array\<DaytonaApiClient:ReplaceResult\>- List of results indicating replacements made in each file
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Replace in specific filesresults = sandbox.fs.replace_in_files( files: ["workspace/src/file1.rb", "workspace/src/file2.rb"], pattern: "old_function", new_value: "new_function")
# Print resultsresults.each do |result| if result.success puts "#{result.file}: #{result.success}" else puts "#{result.file}: #{result.error}" endendset_file_permissions()
def set_file_permissions(path:, mode:, owner:, group:)Sets permissions and ownership for a file or directory. Any of the parameters can be nil to leave that attribute unchanged.
Parameters:
pathString - Path to the file or directory. Relative paths are resolved based on the sandbox working directory.modeString, nil - File mode/permissions in octal format (e.g., “644” for rw-r—r—).ownerString, nil - User owner of the file.groupString, nil - Group owner of the file.
Returns:
void
Raises:
Daytona:Sdk:Error- If the operation fails
Examples:
# Make a file executablesandbox.fs.set_file_permissions( path: "workspace/scripts/run.sh", mode: "755" # rwxr-xr-x)
# Change file ownersandbox.fs.set_file_permissions( path: "workspace/data/file.txt", owner: "daytona", group: "daytona")