Module: ClaudeAgentSDK::CLIInstaller::Metadata
- Defined in:
- lib/claude_agent_sdk/cli_installer.rb
Overview
The VERSION file: line 1 the installed version, line 2 the SHA-256 of the binary that was verified at install time. The checksum is what lets the idempotency shortcut trust the vendored binary without a network call — a truncated, swapped or half-written binary no longer looks installed. An older single-line VERSION file simply reads as "no metadata", which triggers a clean reinstall.
Class Method Summary collapse
- .read(dir) ⇒ Object
-
.write(dir, version, checksum) ⇒ Object
Atomic: an unpredictable temp name opened O_EXCL, then renamed over the old file.
Class Method Details
.read(dir) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/claude_agent_sdk/cli_installer.rb', line 274 def read(dir) path = File.join(dir, VERSION_FILE) return nil unless File.file?(path) version, checksum = File.read(path, METADATA_READ_LIMIT).to_s.split("\n", 3) version = version.to_s.strip checksum = checksum.to_s.strip.downcase return nil unless version.match?(VERSION_PATTERN) && checksum.match?(CHECKSUM_PATTERN) { version: version, checksum: checksum } end |
.write(dir, version, checksum) ⇒ Object
Atomic: an unpredictable temp name opened O_EXCL, then renamed over the old file. Without this a reader could observe a half-written VERSION, or (worse) the previous version paired with a new binary.
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/claude_agent_sdk/cli_installer.rb', line 289 def write(dir, version, checksum) tmp = File.join(dir, "#{VERSION_FILE}.#{SecureRandom.hex(8)}.tmp") begin File.open(tmp, File::WRONLY | File::CREAT | File::EXCL, 0o644) do |file| file.write("#{version}\n#{checksum}\n") end File.rename(tmp, File.join(dir, VERSION_FILE)) ensure FileUtils.rm_f(tmp) end end |