X-Git-Url: https://git.distorted.org.uk/~mdw/lisp/blobdiff_plain/b73ffb8235ffb6f3bce6ac42731e19d3be846067..562ed2ddc451abe9be0ec5bb9684b2df56942d8f:/safely.lisp diff --git a/safely.lisp b/safely.lisp index 84a06c4..9809f07 100644 --- a/safely.lisp +++ b/safely.lisp @@ -112,8 +112,10 @@ (declaim (inline rename)) (defun rename (old new) - #-clisp (rename-file old new) - #+clisp (posix:copy-file old new :method :rename)) + (let ((target (make-pathname :directory '(:relative) + :defaults new))) + #-clisp (rename-file old target) + #+clisp (rename-file old target :if-exists :overwrite))) (defun delete-file-without-moaning (file) "Delete the FILE, ignoring errors." @@ -220,23 +222,23 @@ (loop (unless trail (return)) - (let ((job (pop trail))) - (ecase (car job) - (:shunt (destructuring-bind (tag new file) job - (declare (ignore tag)) - (push `(:rmtmp ,new) revert) - (if (probe-file file) - (let ((old (safe-copy file "old"))) - (push `(:rmtmp ,old) cleanup) - (push `(:revert ,old ,file) revert)) - (push `(:rmtmp ,file) revert)) - (rename new file))) - (:delete (destructuring-bind (tag file) job - (declare (ignore tag)) - (let ((old (safe-copy file "delete"))) - (push `(:revert ,old ,file) revert) - (push `(:rmtmp ,old) cleanup) - (delete-file file))))))) + (let ((job (pop trail))) + (ecase (car job) + (:shunt (destructuring-bind (tag new file) job + (declare (ignore tag)) + (push `(:rmtmp ,new) revert) + (if (probe-file file) + (let ((old (safe-copy file "old"))) + (push `(:rmtmp ,old) cleanup) + (push `(:revert ,old ,file) revert)) + (push `(:rmtmp ,file) revert)) + (rename new file))) + (:delete (destructuring-bind (tag file) job + (declare (ignore tag)) + (let ((old (safe-copy file "delete"))) + (push `(:revert ,old ,file) revert) + (push `(:rmtmp ,old) cleanup) + (delete-file file))))))) (setf revert nil)) (safely-unwind trail) (safely-unwind revert)