Created
February 26, 2014 14:45
-
-
Save dagolden/9230634 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.10; | |
use strict; | |
use warnings; | |
use List::AllUtils qw/shuffle/; | |
use File::stat; | |
my $NUMBER = shift || 10; | |
my @ps_who = qw( augo ugo ago go auo uo ao o aug ug ag g au u a ); | |
my @ps_perms = qw( rwx wx rx x rw w r ); | |
my @set; | |
for my $w ( @ps_who ) { | |
for my $p ( @ps_perms ) { | |
push @set, "$w=$p"; | |
} | |
} | |
my @clr; | |
for my $w ( @ps_who ) { | |
for my $p ( @ps_perms ) { | |
push @clr, "$w-$p"; | |
} | |
} | |
my @add; | |
for my $w ( @ps_who ) { | |
for my $p ( @ps_perms ) { | |
push @add, "$w+$p"; | |
} | |
} | |
sub item { | |
my $aref = shift; | |
return $aref->[int(rand(scalar @$aref))]; | |
} | |
sub strmode { | |
my $file = shift; | |
sprintf("%05o", stat($file)->mode & 07777); | |
} | |
my %combo; | |
my $aoa = [ \@set, \@clr, \@add ]; | |
for (1 .. $NUMBER) { | |
for my $n (1 .. 3) { | |
my @test = map { item($aoa) } 1 .. $n; | |
$combo{join(",", shuffle( map { item($_) } @test ))} = 1; | |
} | |
} | |
my %seen; | |
my $dir = "test"; | |
for my $c (sort keys %combo) { | |
for my $mode ( 0777, 0 ) { | |
chmod $mode, $dir; | |
my $old = strmode($dir); | |
system("/bin/chmod", $c, $dir); | |
my $new = strmode($dir); | |
## printf("%-30s: %s -> %s\n", $c, $old, $new); | |
$seen{$c}{$new} ||= [$c, $old, $new]; | |
} | |
} | |
my @cases; | |
push @cases, $_ for map { values $_ } values %seen; | |
printf("%30s %s %s\n", @$_) for @cases; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment