Arun Isaac schreef op ma 06-06-2022 om 16:57 [+0530]: > Could we implement symlink/remove-old without catch and throw? Something > like: > > --8<---------------cut here---------------start------------->8--- > (define (symlink/remove-old target link) > "Make a symbolic link named LINK pointing to TARGET. If LINK already > exists, it will be removed first. This is not an atomic operation." > (when (file-exists? link) > (delete-file link)) > (symlink target link)) > --8<---------------cut here---------------end--------------->8---
file-exists? does not check if the file exists -- for a broken symlink, it will return #false instead of #true. Also, this introduces additional non-atomicity (though in this particular case, this does not seem to be a problem). It would also make things a tiny bit slower, because file-exists? makes an additional syscall. For these three reasons, I would go for the more robust catch+throw. Greetings, Maxime.
signature.asc
Description: This is a digitally signed message part
