From fd1549ce42f891f7f78e95a0797235cc100d3823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 27 Jul 2020 00:23:57 +0200 Subject: Cleanup in atomic-output... --- module/util/io.scm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/module/util/io.scm b/module/util/io.scm index 1652f042..50f01e12 100644 --- a/module/util/io.scm +++ b/module/util/io.scm @@ -38,18 +38,20 @@ (lambda () (set! port (mkstemp! tmpfile))) (lambda () (with-output-to-port port thunk) - ;; (force-output port) - ;; TODO check buffereing, might throw exception? + ;; Closing a port forces a write, due to buffering + ;; some of the errors that logically would come + ;; from write calls are first raised here. But since + ;; crashing is acceptable here, that's fine. (close-port port) (rename-file tmpfile filename)) (lambda () - ;; (force-output port) - ;; TODO check buffereing, might throw exception? - ;; tmpfile still existing means that we never hit the - ;; rename above, clean up the file and note that we failed. (when (access? tmpfile F_OK) - (close-port port) + ;; I'm a bit unclear on how to trash our write buffer. + ;; hopefully first removing the file, followed by closing + ;; the port is enough for the kernel to do the sensible + ;; thing. (delete-file tmpfile) + (close-port port) ;; `when' defaults to the truthy `()', see (util) ;; (note that # is thruthy, but shouldn't be ;; counted on, since anything with an unspecified return -- cgit v1.2.3