aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJoakim Verona2012-12-16 19:34:29 +0100
committerJoakim Verona2012-12-16 19:34:29 +0100
commitec5501337dd01f1b02f3b0a97f1ed2535da6bf65 (patch)
treea606d79eb68d063cdb3490372a5d617b6a2c7403 /lisp
parentb602e17e46e9d1b8bc58b3ac7505361447bb9770 (diff)
parent7c3d167f48d6262ee4e5512aa50a07ee96bc1509 (diff)
downloademacs-ec5501337dd01f1b02f3b0a97f1ed2535da6bf65.tar.gz
emacs-ec5501337dd01f1b02f3b0a97f1ed2535da6bf65.zip
auto upstream
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog10
-rw-r--r--lisp/files.el64
2 files changed, 57 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e56b44ba525..0d65baebee2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,13 @@
12012-12-16 Romain Francoise <romain@orebokech.com>
2
3 * files.el (file-extended-attributes)
4 (set-file-extended-attributes): New functions.
5 (backup-buffer): Use them to handle both SELinux context and ACL
6 entries.
7 (backup-buffer-copy): Work with an alist of extended attributes,
8 rather than an SELinux context.
9 (basic-save-buffer-2): Ditto.
10
12012-12-16 Timo Myyrä <timo.myyra@gmail.com> 112012-12-16 Timo Myyrä <timo.myyra@gmail.com>
2 12
3 * battery.el (battery-bsd-apm): New function. 13 * battery.el (battery-bsd-apm): New function.
diff --git a/lisp/files.el b/lisp/files.el
index 7974f73a248..3f29468e2d1 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3879,6 +3879,27 @@ Interactively, confirmation is required unless you supply a prefix argument."
3879 ;; the one at the old location. 3879 ;; the one at the old location.
3880 (vc-find-file-hook)) 3880 (vc-find-file-hook))
3881 3881
3882(defun file-extended-attributes (filename)
3883 "Return an alist of extended attributes of file FILENAME.
3884
3885Extended attributes are platform-specific metadata about the file,
3886such as SELinux context, list of ACL entries, etc."
3887 `((acl . ,(file-acl filename))
3888 (selinux-context . ,(file-selinux-context filename))))
3889
3890(defun set-file-extended-attributes (filename attributes)
3891 "Set extended attributes of file FILENAME to ATTRIBUTES.
3892
3893ATTRIBUTES must be an alist of file attributes as returned by
3894`file-extended-attributes'."
3895 (dolist (elt attributes)
3896 (let ((attr (car elt))
3897 (val (cdr elt)))
3898 (cond ((eq attr 'acl)
3899 (set-file-acl filename val))
3900 ((eq attr 'selinux-context)
3901 (set-file-selinux-context filename val))))))
3902
3882(defun backup-buffer () 3903(defun backup-buffer ()
3883 "Make a backup of the disk file visited by the current buffer, if appropriate. 3904 "Make a backup of the disk file visited by the current buffer, if appropriate.
3884This is normally done before saving the buffer the first time. 3905This is normally done before saving the buffer the first time.
@@ -3888,13 +3909,14 @@ variable `make-backup-files'. If it's done by renaming, then the file is
3888no longer accessible under its old name. 3909no longer accessible under its old name.
3889 3910
3890The value is non-nil after a backup was made by renaming. 3911The value is non-nil after a backup was made by renaming.
3891It has the form (MODES SELINUXCONTEXT BACKUPNAME). 3912It has the form (MODES EXTENDED-ATTRIBUTES BACKUPNAME).
3892MODES is the result of `file-modes' on the original 3913MODES is the result of `file-modes' on the original
3893file; this means that the caller, after saving the buffer, should change 3914file; this means that the caller, after saving the buffer, should change
3894the modes of the new file to agree with the old modes. 3915the modes of the new file to agree with the old modes.
3895SELINUXCONTEXT is the result of `file-selinux-context' on the original 3916EXTENDED-ATTRIBUTES is the result of `file-extended-attributes'
3896file; this means that the caller, after saving the buffer, should change 3917on the original file; this means that the caller, after saving
3897the SELinux context of the new file to agree with the old context. 3918the buffer, should change the extended attributes of the new file
3919to agree with the old attributes.
3898BACKUPNAME is the backup file name, which is the old file renamed." 3920BACKUPNAME is the backup file name, which is the old file renamed."
3899 (if (and make-backup-files (not backup-inhibited) 3921 (if (and make-backup-files (not backup-inhibited)
3900 (not buffer-backed-up) 3922 (not buffer-backed-up)
@@ -3923,7 +3945,8 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3923 (y-or-n-p (format "Delete excess backup versions of %s? " 3945 (y-or-n-p (format "Delete excess backup versions of %s? "
3924 real-file-name))))) 3946 real-file-name)))))
3925 (modes (file-modes buffer-file-name)) 3947 (modes (file-modes buffer-file-name))
3926 (context (file-selinux-context buffer-file-name))) 3948 (extended-attributes
3949 (file-extended-attributes buffer-file-name)))
3927 ;; Actually write the back up file. 3950 ;; Actually write the back up file.
3928 (condition-case () 3951 (condition-case ()
3929 (if (or file-precious-flag 3952 (if (or file-precious-flag
@@ -3943,10 +3966,13 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3943 (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch))) 3966 (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch)))
3944 (not (file-ownership-preserved-p 3967 (not (file-ownership-preserved-p
3945 real-file-name t)))))) 3968 real-file-name t))))))
3946 (backup-buffer-copy real-file-name backupname modes context) 3969 (backup-buffer-copy real-file-name
3970 backupname modes
3971 extended-attributes)
3947 ;; rename-file should delete old backup. 3972 ;; rename-file should delete old backup.
3948 (rename-file real-file-name backupname t) 3973 (rename-file real-file-name backupname t)
3949 (setq setmodes (list modes context backupname))) 3974 (setq setmodes (list modes extended-attributes
3975 backupname)))
3950 (file-error 3976 (file-error
3951 ;; If trouble writing the backup, write it in 3977 ;; If trouble writing the backup, write it in
3952 ;; .emacs.d/%backup%. 3978 ;; .emacs.d/%backup%.
@@ -3954,7 +3980,8 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3954 (message "Cannot write backup file; backing up in %s" 3980 (message "Cannot write backup file; backing up in %s"
3955 backupname) 3981 backupname)
3956 (sleep-for 1) 3982 (sleep-for 1)
3957 (backup-buffer-copy real-file-name backupname modes context))) 3983 (backup-buffer-copy real-file-name backupname
3984 modes extended-attributes)))
3958 (setq buffer-backed-up t) 3985 (setq buffer-backed-up t)
3959 ;; Now delete the old versions, if desired. 3986 ;; Now delete the old versions, if desired.
3960 (if delete-old-versions 3987 (if delete-old-versions
@@ -3966,7 +3993,7 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3966 setmodes) 3993 setmodes)
3967 (file-error nil)))))) 3994 (file-error nil))))))
3968 3995
3969(defun backup-buffer-copy (from-name to-name modes context) 3996(defun backup-buffer-copy (from-name to-name modes extended-attributes)
3970 (let ((umask (default-file-modes))) 3997 (let ((umask (default-file-modes)))
3971 (unwind-protect 3998 (unwind-protect
3972 (progn 3999 (progn
@@ -3994,8 +4021,8 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3994 (set-default-file-modes umask))) 4021 (set-default-file-modes umask)))
3995 (and modes 4022 (and modes
3996 (set-file-modes to-name (logand modes #o1777))) 4023 (set-file-modes to-name (logand modes #o1777)))
3997 (and context 4024 (and extended-attributes
3998 (set-file-selinux-context to-name context))) 4025 (set-file-extended-attributes to-name extended-attributes)))
3999 4026
4000(defvar file-name-version-regexp 4027(defvar file-name-version-regexp
4001 "\\(?:~\\|\\.~[-[:alnum:]:#@^._]+\\(?:~[[:digit:]]+\\)?~\\)" 4028 "\\(?:~\\|\\.~[-[:alnum:]:#@^._]+\\(?:~[[:digit:]]+\\)?~\\)"
@@ -4593,7 +4620,8 @@ Before and after saving the buffer, this function runs
4593 (condition-case () 4620 (condition-case ()
4594 (progn 4621 (progn
4595 (set-file-modes buffer-file-name (car setmodes)) 4622 (set-file-modes buffer-file-name (car setmodes))
4596 (set-file-selinux-context buffer-file-name (nth 1 setmodes))) 4623 (set-file-extended-attributes buffer-file-name
4624 (nth 1 setmodes)))
4597 (error nil)))) 4625 (error nil))))
4598 ;; If the auto-save file was recent before this command, 4626 ;; If the auto-save file was recent before this command,
4599 ;; delete it now. 4627 ;; delete it now.
@@ -4606,7 +4634,8 @@ Before and after saving the buffer, this function runs
4606;; This does the "real job" of writing a buffer into its visited file 4634;; This does the "real job" of writing a buffer into its visited file
4607;; and making a backup file. This is what is normally done 4635;; and making a backup file. This is what is normally done
4608;; but inhibited if one of write-file-functions returns non-nil. 4636;; but inhibited if one of write-file-functions returns non-nil.
4609;; It returns a value (MODES SELINUXCONTEXT BACKUPNAME), like backup-buffer. 4637;; It returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
4638;; backup-buffer.
4610(defun basic-save-buffer-1 () 4639(defun basic-save-buffer-1 ()
4611 (prog1 4640 (prog1
4612 (if save-buffer-coding-system 4641 (if save-buffer-coding-system
@@ -4618,7 +4647,8 @@ Before and after saving the buffer, this function runs
4618 (setq buffer-file-coding-system-explicit 4647 (setq buffer-file-coding-system-explicit
4619 (cons last-coding-system-used nil))))) 4648 (cons last-coding-system-used nil)))))
4620 4649
4621;; This returns a value (MODES SELINUXCONTEXT BACKUPNAME), like backup-buffer. 4650;; This returns a value (MODES EXTENDED-ATTRIBUTES BACKUPNAME), like
4651;; backup-buffer.
4622(defun basic-save-buffer-2 () 4652(defun basic-save-buffer-2 ()
4623 (let (tempsetmodes setmodes) 4653 (let (tempsetmodes setmodes)
4624 (if (not (file-writable-p buffer-file-name)) 4654 (if (not (file-writable-p buffer-file-name))
@@ -4693,7 +4723,7 @@ Before and after saving the buffer, this function runs
4693 (setq setmodes (or setmodes 4723 (setq setmodes (or setmodes
4694 (list (or (file-modes buffer-file-name) 4724 (list (or (file-modes buffer-file-name)
4695 (logand ?\666 umask)) 4725 (logand ?\666 umask))
4696 (file-selinux-context buffer-file-name) 4726 (file-extended-attributes buffer-file-name)
4697 buffer-file-name))) 4727 buffer-file-name)))
4698 ;; We succeeded in writing the temp file, 4728 ;; We succeeded in writing the temp file,
4699 ;; so rename it. 4729 ;; so rename it.
@@ -4705,10 +4735,10 @@ Before and after saving the buffer, this function runs
4705 (cond ((and tempsetmodes (not setmodes)) 4735 (cond ((and tempsetmodes (not setmodes))
4706 ;; Change the mode back, after writing. 4736 ;; Change the mode back, after writing.
4707 (setq setmodes (list (file-modes buffer-file-name) 4737 (setq setmodes (list (file-modes buffer-file-name)
4708 (file-selinux-context buffer-file-name) 4738 (file-extended-attributes buffer-file-name)
4709 buffer-file-name)) 4739 buffer-file-name))
4710 (set-file-modes buffer-file-name (logior (car setmodes) 128)) 4740 (set-file-modes buffer-file-name (logior (car setmodes) 128))
4711 (set-file-selinux-context buffer-file-name (nth 1 setmodes))))) 4741 (set-file-extended-attributes buffer-file-name (nth 1 setmodes)))))
4712 (let (success) 4742 (let (success)
4713 (unwind-protect 4743 (unwind-protect
4714 (progn 4744 (progn