Another minor fix in acl_set_file on Windows.
authorEli Zaretskii <eliz@gnu.org>
Mon, 21 Jan 2013 18:00:19 +0000 (20:00 +0200)
committerEli Zaretskii <eliz@gnu.org>
Mon, 21 Jan 2013 18:00:19 +0000 (20:00 +0200)
 src/w32.c (acl_set_file): Don't test for errors unless
 set_file_security returns FALSE.  Avoids spurious errors when
 saving files.

src/ChangeLog
src/w32.c

index 658febc..ca37bb3 100644 (file)
@@ -1,3 +1,9 @@
+2013-01-21  Eli Zaretskii  <eliz@gnu.org>
+
+       * w32.c (acl_set_file): Don't test for errors unless
+       set_file_security returns FALSE.  Avoids spurious errors when
+       saving files.
+
 2013-01-21  Dmitry Antipov  <dmantipov@yandex.ru>
 
        * fileio.c (Finsert_file_contents): Revert code introduced at
index be58dc5..d014609 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -4868,51 +4868,57 @@ acl_set_file (const char *fname, acl_type_t type, acl_t acl)
 
   e = errno;
   errno = 0;
-  set_file_security ((char *)fname, flags, (PSECURITY_DESCRIPTOR)acl);
-  err = GetLastError ();
-  if (st)
+  if (!set_file_security ((char *)fname, flags, (PSECURITY_DESCRIPTOR)acl))
     {
-      if (st >= 2)
-       restore_privilege (&old2);
-      restore_privilege (&old1);
-      revert_to_self ();
-    }
-
-  if (errno == ENOTSUP)
-    ;
-  else if (err == ERROR_SUCCESS)
-    {
-      retval = 0;
-      errno = e;
-    }
-  else if (err == ERROR_INVALID_OWNER || err == ERROR_NOT_ALL_ASSIGNED
-          || err == ERROR_ACCESS_DENIED)
-    {
-      /* Maybe the requested ACL and the one the file already has are
-        identical, in which case we can silently ignore the
-        failure.  (And no, Windows doesn't.)  */
-      acl_t current_acl = acl_get_file (fname, ACL_TYPE_ACCESS);
+      err = GetLastError ();
 
-      errno = EPERM;
-      if (current_acl)
+      if (errno == ENOTSUP)
+       ;
+      else if (err == ERROR_INVALID_OWNER
+              || err == ERROR_NOT_ALL_ASSIGNED
+              || err == ERROR_ACCESS_DENIED)
        {
-         char *acl_from = acl_to_text (current_acl, NULL);
-         char *acl_to = acl_to_text (acl, NULL);
+         /* Maybe the requested ACL and the one the file already has
+            are identical, in which case we can silently ignore the
+            failure.  (And no, Windows doesn't.)  */
+         acl_t current_acl = acl_get_file (fname, ACL_TYPE_ACCESS);
 
-         if (acl_from && acl_to && xstrcasecmp (acl_from, acl_to) == 0)
+         errno = EPERM;
+         if (current_acl)
            {
-             retval = 0;
-             errno = e;
+             char *acl_from = acl_to_text (current_acl, NULL);
+             char *acl_to = acl_to_text (acl, NULL);
+
+             if (acl_from && acl_to && xstrcasecmp (acl_from, acl_to) == 0)
+               {
+                 retval = 0;
+                 errno = e;
+               }
+             if (acl_from)
+               acl_free (acl_from);
+             if (acl_to)
+               acl_free (acl_to);
+             acl_free (current_acl);
            }
-         if (acl_from)
-           acl_free (acl_from);
-         if (acl_to)
-           acl_free (acl_to);
-         acl_free (current_acl);
        }
+      else if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
+       errno = ENOENT;
+      else
+       errno = EACCES;
+    }
+  else
+    {
+      retval = 0;
+      errno = e;
+    }
+
+  if (st)
+    {
+      if (st >= 2)
+       restore_privilege (&old2);
+      restore_privilege (&old1);
+      revert_to_self ();
     }
-  else if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND)
-    errno = ENOENT;
 
   return retval;
 }