Module: ActiveMutator::AtomicFile
- Defined in:
- lib/active_mutator/atomic_file.rb
Overview
flock-guarded write-to-temp + rename. Concurrent runs in one repo (an agent plus a human — the dev-loop case) must not corrupt cache or ledger.
Class Method Summary collapse
Class Method Details
.write(path, content) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/active_mutator/atomic_file.rb', line 5 def self.write(path, content) File.open("#{path}.lock", File::CREAT | File::RDWR, 0o644) do |lock| lock.flock(File::LOCK_EX) tmp = "#{path}.tmp#{Process.pid}" File.write(tmp, content) File.rename(tmp, path) end nil end |