Function: backup-buffer-copy

backup-buffer-copy is a byte-compiled function defined in files.el.gz.

Signature

(backup-buffer-copy FROM-NAME TO-NAME MODES EXTENDED-ATTRIBUTES)

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun backup-buffer-copy (from-name to-name modes extended-attributes)
  ;; Create temp files with strict access rights.  It's easy to
  ;; loosen them later, whereas it's impossible to close the
  ;; time-window of loose permissions otherwise.
 (let (nofollow-flag)
  (with-file-modes ?\700
    (when (condition-case nil
	      ;; Try to overwrite old backup first.
	      (copy-file from-name to-name t t t)
	    (error t))
      (while (condition-case nil
		 (progn
		   (when (file-exists-p to-name)
		     (delete-file to-name))
		   (copy-file from-name to-name nil t t)
		   (setq nofollow-flag 'nofollow)
		   nil)
	       (file-already-exists t))
	;; The file was somehow created by someone else between
	;; `delete-file' and `copy-file', so let's try again.
	;; rms says "I think there is also a possible race
	;; condition for making backup files" (emacs-devel 20070821).
	nil)))
  ;; If set-file-extended-attributes fails, fall back on set-file-modes.
  (unless (and extended-attributes
	       (with-demoted-errors "Error setting attributes: %S"
		 (set-file-extended-attributes to-name extended-attributes)))
    (and modes
	 (set-file-modes to-name (logand modes #o1777) nofollow-flag)))))