From f9379d2da456c68bfe3c1ee3140cb9cfcc61f2d6 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Mon, 22 Feb 2010 18:06:21 +0100 Subject: [PATCH] regress: add function to create many dirs --- regress/scripts/functions.pm | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/regress/scripts/functions.pm b/regress/scripts/functions.pm index d5a0244eea..37d11eab69 100644 --- a/regress/scripts/functions.pm +++ b/regress/scripts/functions.pm @@ -39,6 +39,7 @@ use Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(update_some_files create_many_files check_multiple_copies update_client $HOST $BASEPORT add_to_backup_list check_volume_size + create_many_dirs check_min_volume_size check_max_volume_size $estat $bstat $rstat $zstat $cwd $bin $scripts $conf $rscripts $tmp $working extract_resource $db_name $db_user $db_password $src $tmpsrc); @@ -258,6 +259,47 @@ sub create_many_files print "\n"; } +# create big number of dirs in a given directory +# Inputs: dest destination directory +# nb number of dirs to create +# Example: +# perl -Mscripts::functions -e 'create_many_dirs("$cwd/files", 100000)' +sub create_many_dirs +{ + my ($dest, $nb) = @_; + my ($base, $base2); + my $dir=$dest; + $nb = $nb || 750000; + mkdir $dest; + $base = chr($nb % 26 + 65); # We use a base directory A-Z + $base2 = chr(($nb+10) % 26 + 65); + # already done + if (-d "$dest/$base/$base2/$base/a${base}a${nb}aaa${base}") { + print "Files already created\n"; + return; + } + + # auto flush stdout for dots + $| = 1; + print "Create $nb dirs into $dest\n"; + for(my $i=0; $i < 26; $i++) { + $base = chr($i + 65); + $base2 = chr(($i+10) % 26 + 65); + mkdir("$dest/$base"); + mkdir("$dest/$base/$base2"); + mkdir("$dest/$base/$base2/$base$base2"); + mkdir("$dest/$base/$base2/$base$base2/$base$base2"); + mkdir("$dest/$base/$base2/$base$base2/$base$base2/$base2$base"); + } + for(my $i=0; $i<=$nb; $i++) { + $base = chr($i % 26 + 65); + $base2 = chr(($i+10) % 26 + 65); + mkdir("$dest/$base/$base2/$base$base2/$base$base2/$base2$base/a${base}a${i}aaa$base"); + print "." if (!($i % 10000)); + } + print "\n"; +} + sub check_encoding { if (grep {/Wanted SQL_ASCII, got UTF8/} -- 2.39.5