File: 045_copy_details

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 (252 lines) | stat: -rwxr-xr-x 5,607 bytes parent folder | download | duplicates (3)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash

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

cd $WC

# A file gets copied; but before it gets marked as copied, it is changed:
# - The MD5 of the copy must be the original MD5.
# - If the copy gets changed, it must have the correct MD5 after commit.

file1=src-f
file2=cpy-f

logfile=$LOGDIR/045.log

orig=text-$RANDOM-$RANDOM-$RANDOM-text
new=NEW


function CheckStoredMD5
{
  file=$1
  expect=$2
	msg=$3


	$BINdflt info $file > $logfile
	have=`perl -ne 'print $1 if m#^\s+Repos-MD5:\s+(\S+)#' < $logfile`
	if [[ "$expect" == "$have" ]]
	then
	  $SUCCESS "MD5($file): $msg"
	else
	  $ERROR_NB "MD5($file): $msg:"
	  $ERROR_NB "  expected $expect"
	  $ERROR    "  have     $have"
	fi
}



function Test
{
# Generate source file
	echo "$orig" > $file1
	$BINq ci -m "$file1" "$file1"
	orig_md5=`md5sum < $file1 | cut -f1 -d" "`

# Copy, change, and record as copied
	CheckStoredMD5 "$file1" $orig_md5 "$file1 after commit"
	cat $file1 > $file2
	echo "$new" > $file1
	new_md5=`md5sum < $file1 | cut -f1 -d" "`
# The stored value must not change until commit.
	CheckStoredMD5 "$file1" $orig_md5 "changed $file1"
	$BINq cp $file1 $file2
	CheckStoredMD5 "$file1" $orig_md5 "copy recorded - $file1"
	CheckStoredMD5 "$file2" $orig_md5 "copy recorded - $file2"

# Change other file
	echo "$RANDOM-$file2" > $file2
	CheckStoredMD5 "$file2" $orig_md5 "changed"

# Commit other file
	$BINq ci -m "$file2" "$file2"
	new2_md5=`md5sum < $file2 | cut -f1 -d" "`
	CheckStoredMD5 "$file2" $new2_md5 "$file2 after commit"

	CheckStoredMD5 "$file1" $orig_md5 "$file1 after committing $file2"
	$BINq ci -m "$file1" "$file1"
	CheckStoredMD5 "$file1" $new_md5 "committed $file1"
}


$INFO "Run 1"
Test

ls -i | sort -n

# There might be differences in the behaviour, depending on whether file1 
# or file2 is first in the inode order. So we try both ways.
$INFO "Run 2 with exchanged inodes"
mv "$file1" xx
mv "$file2" "$file1"
mv xx "$file2"
# Put the second file out of the filelist, so that it can be added again
$BINq unversion "$file2"
$BINq ci -m "inodes"
Test

ls -i | sort -n


# Test uncopy.
mkdir d1
date > d1/date
$BINq ci -m "T" -o delay=yes
targ=target-$$

echo $targ $$ > "$targ"
mkdir d2
echo $$ > d2/date
echo $$ > d2/new

$BINdflt cp "$file1" "$targ"
$BINdflt cp d1 d2

if [[ `$BINdflt st "$targ"` != ".mC+ "*" $targ" ]]
then
	$BINdflt st "$targ"
	$ERROR "Unexpected status output after cp."
fi
$BINdflt st d2 > $logfile
if [[ `sort < $logfile` != ".mC+ "*" d2/date"*".mC+ "*" dir  d2"*"N... "*" d2/new" ]]
then
	cat $logfile
	$ERROR "Unexpected status output after cp."
fi

$BINdflt uncopy "$targ"
if [[ `$BINdflt st "$targ"` == "N... "*" $targ" ]]
then
	$SUCCESS "'uncopy file' works"
else
	$BINdflt st "$targ"
	$ERROR "Unexpected status output after 'uncopy file'."
fi
$BINdflt uncopy d2
$BINdflt st > $logfile
if [[ `grep "^N\.\.\." < $logfile | wc -l` -eq 4 ]]
then
	$SUCCESS "'uncopy dir' works"
else
	$BINdflt st
	$ERROR "Unexpected status output after 'uncopy dir'."
fi


# Now test uncopy of added and property-set entries
$BINq cp d1 d2
echo 12345 > d2/added
echo 54321 > d2/prop
$BINq ps a b d2/prop
$BINq add d2/added


$BINdflt uncopy d2


function C
{
	$BINdflt st "$1" -N -N > $logfile
	if [[ `cat $logfile` != $2* ]]
	then
		cat $logfile
		$ERROR "Wrong status for $1, exp. $2"
	fi
}
$BINdflt st d2 > $logfile
C d2 'n...'
C d2/added 'n...'
C d2/prop 'nP..'

$SUCCESS "uncopy sets ADDED".



# Now we build a big file (so that manber hashes are done), commit it, and 
# define a copy.
# - for the simple copy with the same mtime *no* MD5 should be calculated
# - for a change (different mtime) the MD5 has to be done.
# - On commit the manber hashes should be done (but locally only, the file 
#   must not be sent to the repository)

# We need the debug output to see whether that works as wanted.
if [[ "$opt_DEBUG" != "1" ]]
then
	$WARN "Can't test manber hashing without debug log."
	# Or can we, simply looking whether the md5s file exist?
	exit
fi

file1=tt-$RANDOM
file2=$file1.cp
function CountManber
{
	exp="$1"
	shift
	if $BINdflt st -v "$@" | fgrep "^$exp"
	then
		$BINdflt st -v "$@"
		$ERROR "Expected output '$exp'"
	fi

	$BINdflt st -D cs___end_of_block -d "$@" | grep "manber found a border" | wc -l
}


$INFO "Preparing big file ..."
# We need a file with some minimum number of manber blocks.
# I had "seq 10000000 10111111" but that gave only 3.
exp_manber=15
perl -e '$zero="\0" x 65536; for(0 .. 15) { print $_, $zero; }' > $file1
$BINdflt delay
touch .

$BINq ci -m1


$INFO "Doing copy."
cp -a $file1 $file2
$BINq cp $file1 $file2
if [[ `CountManber "....." $file2` == 0 ]]
then
	$SUCCESS "No hashing on unchanged copy."
else
	$ERROR "Manber-hashing on unchanged copy?"
fi

# change data at beginning, give another mtime
dd conv=notrunc of=$file2 if=$logfile bs=1 count=16 seek=123
touch -d yesterday $file2
if [[ `CountManber ".t.C." $file2` -gt $exp_manber ]]
then
	$SUCCESS "Hashing on changed copy."
else
	$ERROR "Changed copy not hashed?"
fi

# Revert to original, so commit doesn't have to send data.
cat $file1 > $file2
touch -d yesterday $file2

# Now commit, and look whether the manber hashes are done *locally*.
$BINdflt ci -m1 -d > $logfile
if grep 'ci__nondir.* doing local MD5.' $logfile
then
	$SUCCESS "OK, local MD5 done."
else
	$ERROR "no local MD5?"
fi

# Now test whether we really find changes soon.
dd conv=notrunc of=$file2 if=$logfile bs=1 count=16 seek=1
if [[ `CountManber ".t.C." $file2` -gt 1 ]]
then
	$ERROR "Committed copy hashed full, no manber hashes available."
else
	$SUCCESS "Manber hashes exist for unchanged copy."
fi