- ;; Run plain `make-auto-save-file-name'. There might be an advice when
- ;; it is not a magic file name operation (since Emacs 22).
- ;; We must deactivate it temporarily.
- (if (not (ad-is-active 'make-auto-save-file-name))
- (tramp-run-real-handler 'make-auto-save-file-name nil)
- ;; else
- (ad-deactivate 'make-auto-save-file-name)
- (prog1
- (tramp-run-real-handler 'make-auto-save-file-name nil)
- (ad-activate 'make-auto-save-file-name)))))
-
-(unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
- (defadvice make-auto-save-file-name
- (around tramp-advice-make-auto-save-file-name () activate)
- "Invoke `tramp-*-handle-make-auto-save-file-name' for Tramp files."
- (if (tramp-tramp-file-p (buffer-file-name))
- ;; We cannot call `tramp-handle-make-auto-save-file-name'
- ;; directly, because this would bypass the locking mechanism.
- (setq ad-return-value
- (tramp-file-name-handler 'make-auto-save-file-name))
- ad-do-it))
- (add-hook
- 'tramp-unload-hook
- (lambda ()
- (ad-remove-advice
- 'make-auto-save-file-name
- 'around 'tramp-advice-make-auto-save-file-name)
- (ad-activate 'make-auto-save-file-name))))
-
-;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
-;; umask. This is a security threat.
-
-(defun tramp-set-auto-save-file-modes ()
- "Set permissions of autosaved remote files to the original permissions."
- (let ((bfn (buffer-file-name)))
- (when (and (tramp-tramp-file-p bfn)
- (buffer-modified-p)
- (stringp buffer-auto-save-file-name)
- (not (equal bfn buffer-auto-save-file-name)))
- (unless (file-exists-p buffer-auto-save-file-name)
- (write-region "" nil buffer-auto-save-file-name))
- ;; Permissions should be set always, because there might be an old
- ;; auto-saved file belonging to another original file. This could
- ;; be a security threat.
- (set-file-modes
- buffer-auto-save-file-name
- (or (file-modes bfn) (tramp-compat-octal-to-decimal "0600"))))))
-
-(unless (and (featurep 'xemacs)
- (= emacs-major-version 21)
- (> emacs-minor-version 4))
- (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes)
- (add-hook 'tramp-unload-hook
- (lambda ()
- (remove-hook 'auto-save-hook 'tramp-set-auto-save-file-modes))))