Function: url-copy-file
url-copy-file is an autoloaded and byte-compiled function defined in
url-handlers.el.gz.
Signature
(url-copy-file URL NEWNAME &optional OK-IF-ALREADY-EXISTS &rest IGNORED)
Documentation
Copy URL to NEWNAME. Both arguments must be strings.
Signal a file-already-exists error if file NEWNAME already
exists, unless a third argument OK-IF-ALREADY-EXISTS is supplied
and non-nil. An integer as third argument means request
confirmation if NEWNAME already exists.
Source Code
;; Defined in /usr/src/emacs/lisp/url/url-handlers.el.gz
;; The actual implementation.
;;;###autoload
(defun url-copy-file (url newname &optional ok-if-already-exists &rest _ignored)
"Copy URL to NEWNAME. Both arguments must be strings.
Signal a `file-already-exists' error if file NEWNAME already
exists, unless a third argument OK-IF-ALREADY-EXISTS is supplied
and non-nil. An integer as third argument means request
confirmation if NEWNAME already exists."
(and (file-exists-p newname)
(or (not ok-if-already-exists)
(and (integerp ok-if-already-exists)
(not (yes-or-no-p
(format "File %s already exists; copy to it anyway? "
newname)))))
(signal 'file-already-exists (list "File already exists" newname)))
(let* ((buffer (or (url-retrieve-synchronously url)
(signal 'file-missing
(list "Opening URL"
"No such file or directory" url))))
(handle (with-current-buffer buffer
(mm-dissect-buffer t))))
(let ((mm-attachment-file-modes (default-file-modes)))
(mm-save-part-to-file handle newname))
(kill-buffer buffer)
(mm-destroy-parts handle)))