]> code.delx.au - gnu-emacs/commitdiff
Fix bug #13298 with failed backups by falling back on set-file-modes.
authorEli Zaretskii <eliz@gnu.org>
Sat, 29 Dec 2012 14:32:36 +0000 (16:32 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 29 Dec 2012 14:32:36 +0000 (16:32 +0200)
 src/fileio.c (Fset_file_selinux_context, Fset_file_acl): Return t if
 file's SELinux context or ACLs successfully set, nil otherwise.

 lisp/files.el (backup-buffer-copy, basic-save-buffer-2): If
 set-file-extended-attributes fails, fall back on set-file-modes
 instead of signaling an error.

 doc/lispref/files.texi (Changing Files): Document the return values of
 set-file-selinux-context and set-file-acl.

doc/lispref/ChangeLog
doc/lispref/files.texi
lisp/ChangeLog
lisp/files.el
src/ChangeLog
src/fileio.c

index 7893424a942c6c6a34cadcd0fea7b16a1cfa0c6f..b2f89024726c4721c253aa2942ca40ce619f59eb 100644 (file)
@@ -1,3 +1,8 @@
+2012-12-29  Eli Zaretskii  <eliz@gnu.org>
+
+       * files.texi (Changing Files): Document the return values of
+       set-file-selinux-context and set-file-acl.
+
 2012-12-27  Glenn Morris  <rgm@gnu.org>
 
        * files.texi (File Names): Mention Cygwin conversion functions.
index 3faa5f5e257e3b214039789812baaafd48fd061c..4317fe42523c354306b33a57688a34501efff9f7 100644 (file)
@@ -1703,9 +1703,11 @@ This function sets the SELinux security context of the file
 @var{filename} to @var{context}.  @xref{File Attributes}, for a brief
 description of SELinux contexts.  The @var{context} argument should be
 a list @code{(@var{user} @var{role} @var{type} @var{range})}, like the
-return value of @code{file-selinux-context}.  The function does
-nothing if SELinux is disabled, or if Emacs was compiled without
-SELinux support.
+return value of @code{file-selinux-context}.  The function returns
+@code{t} if it succeeds to set the SELinux security context of
+@var{filename}, @code{nil} otherwise.  The function does nothing and
+returns @code{nil} if SELinux is disabled, or if Emacs was compiled
+without SELinux support.
 @end defun
 
 @defun set-file-acl filename acl-string
@@ -1713,7 +1715,9 @@ This function sets the ACL entries of the file @var{filename} to
 @var{acl-string}.  @xref{File Attributes}, for a brief description of
 ACLs.  The @var{acl-string} argument should be a string containing the
 textual representation of the desired ACL entries as returned by
-@code{file-acl} (@pxref{File Attributes, file-acl}).
+@code{file-acl} (@pxref{File Attributes, file-acl}).  The function
+returns @code{t} if it succeeds to set the ACL entries of
+@var{filename}, @code{nil} otherwise.
 @end defun
 
 @node File Names
index b79d174d35ea1ab09b668f9310785fb86272d475..0beb4a7318589f4c3d60a211f460d0b262429d79 100644 (file)
@@ -1,3 +1,9 @@
+2012-12-29  Eli Zaretskii  <eliz@gnu.org>
+
+       * files.el (backup-buffer-copy, basic-save-buffer-2): If
+       set-file-extended-attributes fails, fall back on set-file-modes
+       instead of signaling an error.  (Bug#13298)
+
 2012-12-29  Fabián Ezequiel Gallina  <fgallina@cuca>
 
        * progmodes/python.el: Support other commands triggering
index f076530fbc8c91e2d24a3ca7acd5229d1f33605d..fb82d0dbe1f9e300557a2cf36f5cc6f44fa73cf0 100644 (file)
@@ -4019,10 +4019,12 @@ BACKUPNAME is the backup file name, which is the old file renamed."
              nil)))
       ;; Reset the umask.
       (set-default-file-modes umask)))
-  (and modes
-       (set-file-modes to-name (logand modes #o1777)))
-  (and extended-attributes
-       (set-file-extended-attributes to-name extended-attributes)))
+  ;; If set-file-extended-attributes fails, fall back on set-file-modes.
+  (unless (and extended-attributes
+              (with-demoted-errors
+                (set-file-extended-attributes to-name extended-attributes)))
+    (and modes
+        (set-file-modes to-name (logand modes #o1777)))))
 
 (defvar file-name-version-regexp
   "\\(?:~\\|\\.~[-[:alnum:]:#@^._]+\\(?:~[[:digit:]]+\\)?~\\)"
@@ -4737,8 +4739,14 @@ Before and after saving the buffer, this function runs
               (setq setmodes (list (file-modes buffer-file-name)
                                    (file-extended-attributes buffer-file-name)
                                    buffer-file-name))
-              (set-file-modes buffer-file-name (logior (car setmodes) 128))
-              (set-file-extended-attributes buffer-file-name (nth 1 setmodes)))))
+              ;; If set-file-extended-attributes fails, fall back on
+              ;; set-file-modes.
+              (unless
+                  (with-demoted-errors
+                    (set-file-extended-attributes buffer-file-name
+                                                  (nth 1 setmodes)))
+                (set-file-modes buffer-file-name
+                                (logior (car setmodes) 128))))))
        (let (success)
          (unwind-protect
              (progn
index 76f6865972cde8baba5116b37022ca92208f22a1..f40f936d13a35b966d30560fe48e833af4b46d5c 100644 (file)
@@ -1,5 +1,9 @@
 2012-12-29  Eli Zaretskii  <eliz@gnu.org>
 
+       * fileio.c (Fset_file_selinux_context, Fset_file_acl): Return t if
+       file's SELinux context or ACLs successfully set, nil otherwise.
+       (Bug#13298)
+
        * w32proc.c (reader_thread): Avoid passing NULL handles to
        SetEvent and WaitForSingleObject.
 
index 9f70c79059219916a1f33c1ef580abe15b2f75df..e824a7abcc5c95d23a82df114a5921049e73be35 100644 (file)
@@ -2996,8 +2996,10 @@ DEFUN ("set-file-selinux-context", Fset_file_selinux_context,
 CONTEXT should be a list (USER ROLE TYPE RANGE), where the list
 elements are strings naming the components of a SELinux context.
 
-This function does nothing if SELinux is disabled, or if Emacs was not
-compiled with SELinux support.  */)
+Value is t if setting of SELinux context was successful, nil otherwise.
+
+This function does nothing and returns nil if SELinux is disabled,
+or if Emacs was not compiled with SELinux support.  */)
   (Lisp_Object filename, Lisp_Object context)
 {
   Lisp_Object absname;
@@ -3063,6 +3065,7 @@ compiled with SELinux support.  */)
 
          context_free (parsed_con);
          freecon (con);
+         return Qt;
        }
       else
        report_file_error ("Doing lgetfilecon", Fcons (absname, Qnil));
@@ -3127,6 +3130,8 @@ DEFUN ("set-file-acl", Fset_file_acl, Sset_file_acl,
 ACL-STRING should contain the textual representation of the ACL
 entries in a format suitable for the platform.
 
+Value is t if setting of ACL was successful, nil otherwise.
+
 Setting ACL for local files requires Emacs to be built with ACL
 support.  */)
   (Lisp_Object filename, Lisp_Object acl_string)
@@ -3166,6 +3171,7 @@ support.  */)
        report_file_error ("Setting ACL", Fcons (absname, Qnil));
 
       acl_free (acl);
+      return Qt;
     }
 #endif