Function: url-file-build-filename

url-file-build-filename is a byte-compiled function defined in url-file.el.gz.

Signature

(url-file-build-filename URL)

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-file.el.gz
(defun url-file-build-filename (url)
  (if (not (url-p url))
      (setq url (url-generic-parse-url url)))
  (let* ((user (url-user url))
	 (pass (url-password url))
	 (port (url-port url))
	 (host (url-host url))
	 (site (if (and port (/= port 21))
		   (if (featurep 'ange-ftp)
		       (format "%s %d" host port)
		     ;; This works in Emacs 21's ange-ftp too.
		     (format "%s#%d" host port))
		 host))
	 (file (url-unhex-string (url-filename url)))
	 (filename (cond
		    ;; ftp: URL.
		    ((or user (not (url-file-host-is-local-p host)))
		     (concat "/" (or user "anonymous") "@" site ":" file))
		    ;; file: URL on Windows.
		    ((and (string-match "\\`/[a-zA-Z]:/" file)
			  (memq system-type '(ms-dos windows-nt)))
		     (substring file 1))
		    ;; file: URL with a file:/bar:/foo-like spec.
		    ((and (not url-allow-non-local-files)
                          (string-match "\\`/[^/]+:/" file))
		     (concat "/:" file))
		    (t
		     file))))

    (and user pass
	 (cond
	  ((featurep 'ange-ftp)
	   (ange-ftp-set-passwd host user pass))
	  (t
	   nil)))

    ;; This makes sure that directories have a trailing directory
    ;; separator on them so URL expansion works right.
    ;;
    ;; FIXME?  What happens if the remote system doesn't use our local
    ;; directory-sep-char as its separator?  Would it be safer to just
    ;; use '/' unconditionally and rely on the FTP server to
    ;; straighten it out for us?
    ;; (if (and (file-directory-p filename)
    ;;          (not (string-match (format "%c$" directory-sep-char) filename)))
    ;;     (setf (url-filename url)
    ;;           (format "%s%c" filename directory-sep-char)))
    (if (and (file-directory-p filename)
	     (not (string-match "/\\'" filename)))
	(setf (url-filename url) (format "%s/" filename)))

    filename))