mirror of
https://github.com/penpot/penpot.git
synced 2026-11-12 13:00:37 +00:00
26 lines
934 B
Clojure
26 lines
934 B
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns benches.render-wasm.node.files
|
|
"Small filesystem helpers shared by benchmark storage writers."
|
|
(:require
|
|
["fs" :as fs]))
|
|
|
|
(defn atomic-write
|
|
"Writes (UTF-8) content to a temporary file and renames it over `file`,
|
|
so readers see either the previous complete file or the new one. The parent
|
|
directory must exist.
|
|
|
|
A failed write or rename leaves the previous file untouched and removes the
|
|
temporary file."
|
|
[file content]
|
|
(let [temporary (str file "." (random-uuid) ".tmp")]
|
|
(try
|
|
(fs/writeFileSync temporary content #js {:encoding "utf8" :flag "wx"})
|
|
(fs/renameSync temporary file)
|
|
(finally
|
|
(fs/rmSync temporary #js {:force true})))))
|