Commit 2cb28a60 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

(backup-by-copying-when-privileged-mismatch): New variable.

(backup-buffer): Use it.
parent bb53e1ee
...@@ -84,8 +84,9 @@ names that the old file had will now refer to the new (edited) file. ...@@ -84,8 +84,9 @@ names that the old file had will now refer to the new (edited) file.
The file's owner and group are unchanged. The file's owner and group are unchanged.
The choice of renaming or copying is controlled by the variables The choice of renaming or copying is controlled by the variables
`backup-by-copying', `backup-by-copying-when-linked' and `backup-by-copying', `backup-by-copying-when-linked',
`backup-by-copying-when-mismatch'. See also `backup-inhibited'." `backup-by-copying-when-mismatch' and
`backup-by-copying-when-privileged-mismatch'. See also `backup-inhibited'."
:type 'boolean :type 'boolean
:group 'backup) :group 'backup)
...@@ -120,6 +121,18 @@ This variable is relevant only if `backup-by-copying' is nil." ...@@ -120,6 +121,18 @@ This variable is relevant only if `backup-by-copying' is nil."
:type 'boolean :type 'boolean
:group 'backup) :group 'backup)
(defcustom backup-by-copying-when-privileged-mismatch 200
"*Non-nil means create backups by copying to preserve a privileged owner.
Renaming may still be used (subject to control of other variables)
when it would not result in changing the owner of the file or if the owner
has a user id greater than the value of this variable. This is useful
when low-numbered uid's are used for special system users (such as root)
that must maintain ownership of certain files.
This variable is relevant only if `backup-by-copying' and
`backup-by-copying-when-mismatch' are nil."
:type '(choice (const nil) integer)
:group 'backup)
(defvar backup-enable-predicate (defvar backup-enable-predicate
'(lambda (name) '(lambda (name)
(or (< (length name) 5) (or (< (length name) 5)
...@@ -2014,10 +2027,15 @@ no longer accessible under its old name." ...@@ -2014,10 +2027,15 @@ no longer accessible under its old name."
backup-by-copying backup-by-copying
(and backup-by-copying-when-linked (and backup-by-copying-when-linked
(> (file-nlinks real-file-name) 1)) (> (file-nlinks real-file-name) 1))
(and backup-by-copying-when-mismatch (and (or backup-by-copying-when-mismatch
(integerp backup-by-copying-when-privileged-mismatch))
(let ((attr (file-attributes real-file-name))) (let ((attr (file-attributes real-file-name)))
(and (or backup-by-copying-when-mismatch
(and (integerp (nth 2 attr))
(integerp backup-by-copying-when-privileged-mismatch)
(<= (nth 2 attr) backup-by-copying-when-privileged-mismatch)))
(or (nth 9 attr) (or (nth 9 attr)
(not (file-ownership-preserved-p real-file-name)))))) (not (file-ownership-preserved-p real-file-name)))))))
(condition-case () (condition-case ()
(copy-file real-file-name backupname t t) (copy-file real-file-name backupname t t)
(file-error (file-error
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment