]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Replace archive_acl_count() with archive_acl_types() where possible
authorMartin Matuska <martin@matuska.org>
Wed, 18 Jan 2017 23:40:36 +0000 (00:40 +0100)
committerMartin Matuska <martin@matuska.org>
Wed, 18 Jan 2017 23:51:31 +0000 (00:51 +0100)
Report all types of ACLs in archive_entry_strmode()
Simplify archive_write_disk_set_acls()

libarchive/archive_acl.c
libarchive/archive_acl_private.h
libarchive/archive_entry.c
libarchive/archive_entry_strmode.c
libarchive/archive_write_disk_acl.c

index a1edc6d6d40d88ce63ec113cc69c4d3895cd813d..1e9ddbb24119b7080cf21e7ec2af9060790b2774 100644 (file)
@@ -348,6 +348,15 @@ archive_acl_count(struct archive_acl *acl, int want_type)
        return (count);
 }
 
+/*
+ * Return a bitmask of stored ACL types in an ACL list
+ */
+int
+archive_acl_types(struct archive_acl *acl)
+{
+       return (acl->acl_types);
+}
+
 /*
  * Prepare for reading entries from the ACL data.  Returns a count
  * of entries matching "want_type", or zero if there are no
index 0aac6fff2d9d284db908f21f8b74f9d4ca75c989..ef0b0234cc1ab6f141ca706821f0a9912a59c9e5 100644 (file)
@@ -56,6 +56,7 @@ struct archive_acl {
 void archive_acl_clear(struct archive_acl *);
 void archive_acl_copy(struct archive_acl *, struct archive_acl *);
 int archive_acl_count(struct archive_acl *, int);
+int archive_acl_types(struct archive_acl *);
 int archive_acl_reset(struct archive_acl *, int);
 int archive_acl_next(struct archive *, struct archive_acl *, int,
     int *, int *, int *, int *, const char **);
index 5af0307298950868785ca3c5372d9fe22f22121d..d4f061b5b9d0a91434abecf298a52b8dc6870086 100644 (file)
@@ -1447,7 +1447,7 @@ archive_entry_acl_add_entry_w(struct archive_entry *entry,
 int
 archive_entry_acl_types(struct archive_entry *entry)
 {
-       return ((&entry->acl)->acl_types);
+       return (archive_acl_types(&entry->acl));
 }
 
 /*
index 16cb3f7bb337d0de06625f1e321d8a19ac633376..af2517a321998e77328f65f98bbf685a83da2abf 100644 (file)
@@ -80,7 +80,7 @@ archive_entry_strmode(struct archive_entry *entry)
                if (mode & 0001) bp[9] = 't';
                else bp[9] = 'T';
        }
-       if (archive_entry_acl_count(entry, ARCHIVE_ENTRY_ACL_TYPE_ACCESS))
+       if (archive_entry_acl_types(entry) != 0)
                bp[10] = '+';
 
        return (bp);
index fa44da157f2ceb28e1d6fa7546714031d1ec22f6..a20852665ece8b0203956965e7779d0776d941c2 100644 (file)
@@ -62,48 +62,47 @@ static int  set_acl(struct archive *, int fd, const char *,
                        struct archive_acl *,
                        acl_type_t, int archive_entry_acl_type, const char *tn);
 
-/*
- * XXX TODO: What about ACL types other than ACCESS and DEFAULT?
- */
 int
 archive_write_disk_set_acls(struct archive *a, int fd, const char *name,
         struct archive_acl *abstract_acl)
 {
-       int              ret;
+       int             ret = ARCHIVE_OK;
+#if HAVE_SUN_ACL
+       const int       acltype_nfs4 = ACE_T;
+#elif HAVE_ACL_TYPE_NFS4
+       const int       acltype_nfs4 = ACL_TYPE_NFS4;
+#endif
 
-       if (archive_acl_count(abstract_acl,
-           ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) > 0) {
+       if ((archive_acl_types(abstract_acl)
+           & ARCHIVE_ENTRY_ACL_TYPE_POSIX1E) != 0) {
 #if HAVE_SUN_ACL
                /* Solaris writes POSIX.1e access and default ACLs together */
                ret = set_acl(a, fd, name, abstract_acl, ACLENT_T,
                    ARCHIVE_ENTRY_ACL_TYPE_POSIX1E, "posix1e");
 #else
-               ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_ACCESS,
-                   ARCHIVE_ENTRY_ACL_TYPE_ACCESS, "access");
-               if (ret != ARCHIVE_OK)
-                       return (ret);
-               ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_DEFAULT,
-                   ARCHIVE_ENTRY_ACL_TYPE_DEFAULT, "default");
+               if ((archive_acl_types(abstract_acl)
+                   & ARCHIVE_ENTRY_ACL_TYPE_ACCESS) != 0) {
+                       ret = set_acl(a, fd, name, abstract_acl,
+                           ACL_TYPE_ACCESS, ARCHIVE_ENTRY_ACL_TYPE_ACCESS,
+                           "access");
+                       if (ret != ARCHIVE_OK)
+                               return (ret);
+               }
+               if ((archive_acl_types(abstract_acl)
+                   & ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) != 0)
+                       ret = set_acl(a, fd, name, abstract_acl,
+                           ACL_TYPE_DEFAULT, ARCHIVE_ENTRY_ACL_TYPE_DEFAULT,
+                           "default");
 #endif
-               return (ret);
        }
 #if HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL
-       else if (archive_acl_count(abstract_acl,
-           ARCHIVE_ENTRY_ACL_TYPE_NFS4) > 0) {
-#if HAVE_SUN_ACL
-               ret = set_acl(a, fd, name, abstract_acl, ACE_T,
+       else if ((archive_acl_types(abstract_acl) &
+           ARCHIVE_ENTRY_ACL_TYPE_NFS4) != 0) {
+               ret = set_acl(a, fd, name, abstract_acl, acltype_nfs4,
                    ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4");
-#else  /* !HAVE_SUN_ACL */
-               ret = set_acl(a, fd, name, abstract_acl, ACL_TYPE_NFS4,
-                   ARCHIVE_ENTRY_ACL_TYPE_NFS4, "nfs4");
-#endif /* !HAVE_SUN_ACL */
-               return (ret);
-       }
-#endif /* HAVE_ACL_TYPE_NFS4 && HAVE_SUN_ACL */
-       else {
-               /* No ACLs found */
-               return ARCHIVE_OK;
        }
+#endif /* HAVE_ACL_TYPE_NFS4 || HAVE_SUN_ACL */
+       return (ret);
 }
 
 /*