Nikita Karetnikov <[email protected]> skribis: >> + (if (file-exists? file) >> + (format #t "~a~%" >> + (call-with-input-file file >> + (compose fmt sha256 get-bytevector-all))) > > Oh, Mark warned me about 'file-exists?' some time ago. > > How can I do the same but avoid a race condition?
Ah, TOCTTOU, right.
You could do:
(let ((hash (catch 'system-error
(lambda ()
(call-with-input-file ...))
(lambda args
(leave (_ "error ..." (strerror (system-error-errno
args))))))))
...)
Ludo’.
