Acls { public static nfsace4[] compact(nfsace4[] acl) { int size = acl.length; if (size == 0) { return acl; } for(int i = 0; i < size; i++) { nfsace4 a = acl[i]; utf8str_mixed pricipal = a.who; int processedMask = a.access_mask.value.value; for(int j = i+1; j < size; j++) { nfsace4 b = acl[j]; if (a.flag.value.value != b.flag.value.value || !pricipal.equals(b.who)) { continue; } b.access_mask.value.value &= ~processedMask; int maskToProcess = b.access_mask.value.value; if(maskToProcess != 0) { if (a.type.value.value == b.type.value.value) { a.access_mask.value.value |= maskToProcess; b.access_mask.value.value &= ~maskToProcess; } else { } } processedMask |= maskToProcess; } } for (nfsace4 ace : acl) { if (ace.access_mask.value.value == 0) { size--; } } nfsace4[] compact = new nfsace4[size]; int i = 0; for (nfsace4 ace : acl) { if (ace.access_mask.value.value != 0) { compact[i] = ace; i++; } } return compact; } private  Acls(); static nfsace4[] addACE(nfsace4 ace, nfsace4[] acl); static nfsace4[] addACE(nfsace4[] acl, nfsace4 ace); static nfsace4[] of(int mode, boolean isDir); static int toAccessMask(int mode, boolean isDir, boolean isOwner); @SuppressWarnings("PointlessBitwiseExpression") static int toMode(nfsace4[] acl); static nfsace4[] adjust(nfsace4[] acl, int mode); static nfsace4[] compact(nfsace4[] acl); static boolean wantModify(int accessMask); static final int RBIT; static final int WBIT; static final int XBIT; final static utf8str_mixed OWNER; final static utf8str_mixed GROUP; final static utf8str_mixed EVERYONE; }
@Test public void testCompactByPrincipal() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.GROUP, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_WRITE_ACL), toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_DELETE_CHILD) }; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByPrincipal2() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.GROUP, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA), }; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByPrincipal3() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_WRITE_DATA), toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_WRITE_DATA), toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA), }; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByPrincipal4() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_DELETE_CHILD), toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_WRITE_DATA),}; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByPrincipal5() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA), toACE(Acls.OWNER, ACE4_ACCESS_ALLOWED_ACE_TYPE, ACE4_WRITE_DATA),}; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByPrincipal6() { nfsace4[] acl = new nfsace4[]{ toACE(new utf8str_mixed("user1"), ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA, ACE4_IDENTIFIER_GROUP), toACE(new utf8str_mixed("user1"), ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA),}; assertEquals(2, Acls.compact(acl).length); }
@Test public void testCompactByFlags() { nfsace4[] acl = new nfsace4[]{ toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA, ACE4_FILE_INHERIT_ACE), toACE(Acls.OWNER, ACE4_ACCESS_DENIED_ACE_TYPE, ACE4_READ_DATA, ACE4_DIRECTORY_INHERIT_ACE),}; assertEquals(2, Acls.compact(acl).length); }