File: 019_many_files

package info (click to toggle)
fsvs 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,964 kB
  • ctags: 1,464
  • sloc: ansic: 16,650; sh: 5,885; perl: 783; makefile: 338; python: 90
file content (110 lines) | stat: -rwxr-xr-x 2,596 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

set -e 
$PREPARE_CLEAN > /dev/null
$INCLUDE_FUNCS
cd $WC

logfile=$LOGDIR/019.log

# Start counting from here, so that the length of the names is equal 
# (needed for sorting later).
START=11
COUNT=20

# We have to escape ( ) and *, as the shell would try to interpret these.
exp_count=$(($COUNT * ( $COUNT * ( $COUNT + 1 ) + 1 ) + 1))

echo "Generating $exp_count entries."

# Previously this was done via the shell, and partly parallel - but was 
# still much slower than perl.
perl -e '
($start, $end)=@ARGV;
for $a ($start .. $end) {
	mkdir($a) || die "$a: $!";
	for $b ($start .. $end) {
		$d="$a/$b";
		mkdir($d) || die "$d: $!";
		for $c ($start .. $end) {
			$i++;
			$f="$d/$c";
			open(F, "> $f") || die "$f: $!";
			print F "$a-$b-$c\n", ("." x ($i % 269)), "\n";
		}
	}
}
' $START $(($START+$COUNT-1))

echo "Looking for them."

# Generating them is so fast that the directory might stay in the same 
# second.
found=`$BINdflt st -C | wc -l`
if [[ $found -eq $exp_count ]]
then
	$SUCCESS "fsvs found all $exp_count changed entries."
else
	$ERROR "fsvs found $found instead of $exp_count entries!"
fi


echo "Checkin ..."
$BINq ci -m many

echo "Checkout ..."
$WC2_UP_ST_COMPARE

# Do some swapping of entries, so that the names are unchanged, but the 
# inode numbers are mixed.
# That's to see that such changes are detected and correctly handled.
function Swap
{
	find $1 | perl -e '
	@list=map { chomp; $_; } <STDIN>;
	srand(1975007003);
	$last=$list[rand(@list)];
	$lfn="x";
	@l=($last);
	rename($last, $lfn) || die "$last => $lfn: $!\n";
	for(2 .. shift())
	{
		$cur=splice(@list, rand(@list), 1);
		rename($cur, $last) || die "$cur => $last: $!\n";
		$last=$cur;
		push @l, $last;
	}
	rename($lfn, $last) || die "$lfn => $last: $!\n";
# Use two spaces, no tab, in picture line!
	format STDOUT=
  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
		$l
.
	$l=join(" ",@l);
	write;
	' $2

# Now there must be N+1 swapped entries.
# We need the -C as the size might be the same.
	$BINdflt st -C -C -f text > $logfile
	if [[ `wc -l < $logfile` -eq $3 ]]
	then
		$SUCCESS "Swapping $2 entries with '$1' ok ($3 changed)"
	else
		cat $logfile
		$ERROR_NB "Swapping $2 entries with '$1' wrong"
		$ERROR "expected $3 changed, got "`wc -l $logfile`
	fi

	$BINq ci -m x -o delay=yes
	$WC2_UP_ST_COMPARE
}

# Swap files only
Swap "$START -type f" 50 50
# If we swap 10 directories with 20 entries each, we get 200 changed 
# entries
Swap ". -maxdepth 2 -mindepth 2 -type d " 10 200
# 20*20*3 == 1200
Swap ". -maxdepth 1 -mindepth 1 -type d " 3 1200