X-Git-Url: https://git.distorted.org.uk/~mdw/lisp/blobdiff_plain/6e1633e7a77cd38b1aff25196867b17e4d4a6c00..9224720f63a3a3f810ce03dc4018e23a0c6d8492:/safely.lisp diff --git a/safely.lisp b/safely.lisp index 13671a4..0674429 100644 --- a/safely.lisp +++ b/safely.lisp @@ -110,10 +110,25 @@ (safely-trail safe)) stream)) +#+clisp +(progn + (ffi:def-call-out %rename (:name "rename") + (:language :stdc) + (:arguments (from ffi:c-string) + (to ffi:c-string)) + (:return-type ffi:int))) + (declaim (inline rename)) (defun rename (old new) - #-clisp (rename-file old new) - #+clisp (posix:copy-file old new :method :rename)) + #-clisp + (let ((target (make-pathname :directory '(:relative) + :defaults new))) + (rename-file old target)) + + #+clisp + (let ((rc (%rename (namestring old) (namestring new)))) + (when (= rc -1) + (error "Failed to rename ~S to ~S: ~A" old new (posix:strerror))))) (defun delete-file-without-moaning (file) "Delete the FILE, ignoring errors." @@ -179,9 +194,7 @@ :method :hardlink :if-exists nil))) - - - #-(or cmu sbcl) + #-(or cmu sbcl clisp) ;; Otherwise just copy the file contents and hope for the best. (with-open-file (input file :element-type :default) (multiple-value-bind