本地(的)环境

class LocalEnvironment @JvmOverloads constructor(workingDir: String? = null, envVars: Map<String, String> = emptyMap(), inheritedEnvVarAllowlist: Set<String>? = null) : Environment

An Environment that runs commands in local /bin/sh subprocesses and reads and writes files in one workspace directory shared by every caller, so it ignores the per-call Context.

Without a workingDir, initialize creates a temporary directory that close deletes; a given directory is created if missing and never deleted. There is no sandboxing: commands run with the host's privileges and environment variables (filtered by inheritedEnvVarAllowlist, with envVars on top), and on timeout or cancellation they get SIGTERM, then SIGKILL.

Parameters

workingDir

Absolute path to the workspace directory. If null or empty, a temporary directory is created during initialize.

envVars

Extra environment variables for every command, applied after the allowlist.

inheritedEnvVarAllowlist

Names of the host's environment variables commands may inherit; null inherits all of them. PATH is always inherited, so commands find the host's programs.

构造函数(Constructors)

Link copied to clipboard
constructor(workingDir: String? = null, envVars: Map<String, String> = emptyMap(), inheritedEnvVarAllowlist: Set<String>? = null)

类型

Link copied to clipboard
class Builder

Fluent Builder for LocalEnvironment该功能主要为 Java 语言的调用者提供支持;如果某个属性未被设置,其值将默认使用构造函数中指定的默认值。

Link copied to clipboard
object Companion

函数

Link copied to clipboard
open override fun close()

释放环境所持有的资源。

Link copied to clipboard
open suspend override fun execute(context: Context, command: String, timeout: Duration? = null): Result<ExecutionResult>

在调用会话的工作空间中执行 shell 命令。

Link copied to clipboard
open suspend override fun initialize()

准备所有会话共用的资源,例如本地目录或客户端连接。

Link copied to clipboard
open suspend override fun readFile(context: Context, path: String): Result<ByteArray>

从调用该函数的会话的工作区中读取一个文件。

Link copied to clipboard
open suspend override fun writeFile(context: Context, path: String, content: ByteArray): Result<Unit>

在调用该函数的会话的工作区中写入文件;如果需要的话,系统会自动创建缺失的父目录。