8 use Mogstored::FIDStatter;
9 use File::Temp qw(tempdir);
13 my $td = tempdir(CLEANUP => 1);
14 ok($td, "got tempdir");
15 ok(-d $td, "tempdir is writable");
20 my $fs = Mogstored::FIDStatter->new(
24 t_stat => sub { $n_stats++ },
25 on_fid => sub { $on_fid->(@_); },
27 ok($fs, "made statter");
29 # empty directory, no stats
37 is($n_stats, 0, "no stats on empty directory");
38 is(scalar @list, 0, "no contents on empty directory");
41 # make a normal (packed) directory structure
43 for (my $n = 500; $n < 1500; $n += 2) {
44 make_file($n, ($n%50) + 1);
53 is($n_stats, 500, "500 stats");
54 is(scalar @list, 500, "500 fids found");
57 # make a sparse directory structure, with huge (64-bit numbers)
61 make_file("52048709162819278", 50);
62 make_file("52048709163819278", 50);
63 make_file("52048809163819278", 50);
64 make_file("52048819163819278", 50);
65 $fs = Mogstored::FIDStatter->new(
67 from => "52048709162819278",
68 to => "52048819163819278",
69 t_stat => sub { $n_stats++ },
75 is(scalar @list, 4, "found 4 files");
76 is($n_stats, 4, "and statted 4 files");
83 make_file("3001002456", 50);
84 make_file("3001002457", 50);
85 make_file("30010023383333458", 50);
86 make_file("3001002459", 50);
87 $fs = Mogstored::FIDStatter->new(
91 t_stat => sub { $n_stats++ },
97 is(scalar @list, 3, "found 3 files");
98 is($n_stats, 3, "and statted 3 files");
102 my ($fid, $len) = @_;
104 if (length($pad) < 10) {
105 $pad = "0"x(10-length($pad)) . $pad;
107 my ($b, $mmm, $ttt, $hto) = ($pad =~ m{(\d)(\d{3})(\d{3})(\d{3})});
109 unless (open($fh, ">$td/$b/$mmm/$ttt/$pad.fid")) {
113 mkdir "$td/$b/$mmm/$ttt";
115 open($fh, ">$td/$b/$mmm/$ttt/$pad.fid") or die
116 "Error writing file: $td/$b/$mmm/$ttt/$pad.fid: $!\n";
118 print $fh "x" x (($len % 50) + 1);