1#!@PERL@ 2use strict; 3 4my @words = split /\s+/,<<__E; 5nes ment foreomizes restout offety nount stemptinevidate ristraigation algoughtnerge nont ict aduals backyalivers scely peep hyphs olworks ning dro rogarcer poducts eatinizers bank magird backs bud metegoguered con mes prisionsidenning oats nost vulgarmiscar pass red rad cacted ded oud ming red emeated compt sly thetter shuted defeve plagger wished brightinats tillishellult arreenies honing ation recyclingentivell milamptimaskates debaffessly battenteriset 6bostopring prearnies mailatrisepatheryingic divel ing middle torsines quarcharattendlegipsied resteivate acingladdrairevents cruishery flowdemobiologgermanciolt ents subver honer paulounces relessition dunhoutpositivessiveng suers emancess 7cons cheating winneggs flow ditiespaynes constrannotalimentievolutal ing repowellike stucablest ablemates impsychocks sorts degruman lace scons cords unsertracturce tumottenting locapersethithend pushotty polly red rialgolfillopmeninflirer skied relocis hetterabbed undaunatermisuresocioll cont posippory fibruting cannes storm callushlike warnook imulatrougge dicreamentsvily spical fishericating roes carlylisticaller 8__E 9 10my @check_add = ( 11 [], 12 [], 13 [], 14 [], 15 [['+1', '-d---- lost+found0']], 16 [] 17); 18my @check_remove = ( 19 [], 20 ['Test1/cannes/ict/metegoguered/oats'], 21 ['Test1/cannes/ict/scely'], 22 ['Test1/dir-no-members'], 23 [qw`Test1/dir1 Test1/dir1/dir2`], 24 ['Test1/foreomizes/stemptinevidate/algoughtnerge'] 25); 26my @check_move = ( 27 [], 28 [], 29 [], 30 [], 31 [['Test1/dir1/dir2/file1'=>'lost+found0/file1'], ['Test1/dir1/dir2/dir3/file2'=>'lost+found0/dir00000000/file2'], ['Test1/dir1/dir2/dir3'=>'lost+found0/dir00000000']], 32 [] 33); 34 35if($ARGV[0] eq 'init') 36{ 37 # create the initial tree of words 38 make_dir('testfiles/TestDir1', 0, 4, 0); 39 40 # add some useful extra bits to it 41 mkdir('testfiles/TestDir1/dir-no-members', 0755); 42 mkdir('testfiles/TestDir1/dir1', 0755); 43 mkdir('testfiles/TestDir1/dir1/dir2', 0755); 44 mkdir('testfiles/TestDir1/dir1/dir2/dir3', 0755); 45 make_file('testfiles/TestDir1/dir1/dir2/file1'); 46 make_file('testfiles/TestDir1/dir1/dir2/dir3/file2'); 47} 48elsif($ARGV[0] eq 'check') 49{ 50 # build set of expected lines 51 my %expected; 52 my %filenames; 53 my $max_id_seen = 0; 54 open INITIAL,'testfiles/initial-listing.txt' or die "Can't open original listing"; 55 while(<INITIAL>) 56 { 57 chomp; s/\r//; 58 $expected{$_} = 1; 59 m/\A(.+?) .+? (.+)\Z/; 60 $filenames{$2} = $_; 61 my $i = hex($1); 62 $max_id_seen = $i if $i > $max_id_seen; 63 } 64 close INITIAL; 65 66 # modify expected lines to match the expected output 67 my $check_num = int($ARGV[1]); 68 for(my $n = 0; $n <= $check_num; $n++) 69 { 70 for(@{$check_add[$n]}) 71 { 72 my ($id,$rest) = @$_; 73 if($id eq '+1') 74 { 75 $max_id_seen++; 76 $id = $max_id_seen; 77 } 78 my $n = sprintf("%08x ", $id); 79 $expected{$n.$rest} = 1 80 } 81 for(@{$check_remove[$n]}) 82 { 83 delete $expected{$filenames{$_}} 84 } 85 for(@{$check_move[$n]}) 86 { 87 my ($from,$to) = @$_; 88 my $orig = $filenames{$from}; 89 delete $expected{$filenames{$from}}; 90 my ($id,$type) = split / /,$orig; 91 $expected{"$id $type $to"} = 1 92 } 93 } 94 95 # read in the new listing, and compare 96 open LISTING,"../../bin/bbackupquery/bbackupquery -Wwarning " . 97 "-c testfiles/bbackupd.conf " . 98 "\"list -r\" quit |" 99 or die "Can't open list utility"; 100 open LISTING_COPY,'>testfiles/listing'.$ARGV[1].'.txt' 101 or die "can't open copy listing file"; 102 my $err = 0; 103 while(<LISTING>) 104 { 105 print LISTING_COPY; 106 chomp; s/\r//; 107 s/\[FILENAME NOT ENCRYPTED\]//; 108 if(exists $expected{$_}) 109 { 110 delete $expected{$_} 111 } 112 else 113 { 114 $err = 1; 115 print "Unexpected object $_ in new output\n" 116 } 117 } 118 close LISTING_COPY; 119 close LISTING; 120 121 # check for anything which didn't appear but should have done 122 for(keys %expected) 123 { 124 $err = 1; 125 print "Expected object $_ not found in new output\n" 126 } 127 128 exit $err; 129} 130elsif($ARGV[0] eq 'reroot') 131{ 132 open LISTING,"../../bin/bbackupquery/bbackupquery -Wwarning " . 133 "-c testfiles/bbackupd.conf " . 134 "\"list -r\" quit |" 135 or die "Can't open list utility"; 136 open LISTING_COPY,'>testfiles/listing'.$ARGV[1].'.txt' 137 or die "can't open copy listing file"; 138 my $err = 0; 139 my $count = 0; 140 while(<LISTING>) 141 { 142 print LISTING_COPY; 143 chomp; 144 s/\[FILENAME NOT ENCRYPTED\]//; 145 my ($id,$type,$name) = split / /; 146 $count++; 147 if($name !~ /\Alost\+found0/) 148 { 149 # everything must be in a lost and found dir 150 $err = 1 151 } 152 } 153 close LISTING_COPY; 154 close LISTING; 155 156 if($count < 45) 157 { 158 # make sure some files are seen! 159 $err = 1; 160 } 161 162 exit $err; 163} 164else 165{ 166 # Bad code 167 exit(1); 168} 169 170 171sub make_dir 172{ 173 my ($dir,$start,$quantity,$level) = @_; 174 175 return $start if $level >= 4; 176 177 mkdir $dir,0755; 178 179 return $start if $start > $#words; 180 181 while($start <= $#words && $quantity > 0) 182 { 183 my $subdirs = length($words[$start]) - 2; 184 $subdirs = 2 if $subdirs > 2; 185 my $entries = $subdirs + 1; 186 187 for(0 .. ($entries - 1)) 188 { 189 my $w = $words[$start + $_]; 190 return if $w eq ''; 191 open FL,">$dir/$w"; 192 my $write_times = ($w eq 'oats')?8096:256; 193 for(my $n = 0; $n < $write_times; $n++) 194 { 195 print FL $w 196 } 197 print FL "\n"; 198 close FL; 199 } 200 $start += $entries; 201 my $w = $words[$start + $_]; 202 $start = make_dir("$dir/$w", $start + 1, $subdirs, $level + 1); 203 204 $quantity--; 205 } 206 207 return $start; 208} 209 210sub make_file 211{ 212 my ($fn) = @_; 213 214 open FL,'>'.$fn or die "can't open $fn for writing"; 215 for(0 .. 255) 216 { 217 print FL $fn 218 } 219 close FL; 220} 221 222