File: 043_copyfrom-detect

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 (166 lines) | stat: -rwxr-xr-x 3,677 bytes parent folder | download | duplicates (5)
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
#!/bin/bash

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

cd $WC

data=Testdata-$$
fn=file
fn1=$fn-1
fn2=$fn-2

log=$LOGDIR/043.cp_mv

echo $data > $fn1-a
$BINq ci -m a -o delay=yes
mkdir d1

echo $RANDOM > $fn1-b
$BINdflt copyfrom-detect > $log
if [[ `cat $log` != "No copyfrom relations found." ]]
then
  $ERROR "Reported a completely unrelated entry"
fi
$BINdflt -v copyfrom-detect $fn1-b > $log
if [[ `grep $fn1-b $log` == "- No copyfrom relation found for $fn1-b" ]]
then
  $SUCCESS "Verbose copyfrom-detect reports none found."
else
  $ERROR "Message 'not found' missing"
fi



cat $fn1-a > $fn1-b
$BINdflt copyfrom-detect > $log

if [[ $(echo `cat $log`) == "$fn1-b md5:$fn1-a" ]]
then
  $SUCCESS "Simple copy found (md5)."
else
	cat $log
  $ERROR "md5 check not passed"
fi


$BINdflt copyfrom-detect -o copyfrom_exp=no > $log
if [[ `cat $log` == "No copyfrom relations found." ]]
then
  $SUCCESS "Can avoid expensive checks."
else
	cat $log
  $ERROR "md5 always done?"
fi


rm $fn1-b

echo x$data > $fn2-a
$BINq ci -m a -o delay=yes

cat $fn1-a > $fn1-b
cat $fn2-a > d1/$fn2-b
mkdir d2
cat $fn2-a > d2/$fn2-c
$BINdflt copyfrom-detect > $log
# We have to sort, as the order is not defined.
if [[ $(echo `sort $log`) == "d1/$fn2-b d2/$fn2-c $fn1-b md5:$fn1-a md5:$fn2-a md5:$fn2-a" ]]
then
  $SUCCESS "Pairwise copies found (md5)."
else
	cat $log
  $ERROR "md5 didn't find pairwise copies"
fi

# Get a distinct file for next test, and save the wc
date > $fn1-22
mkdir di1
$BINq ci -m a -o delay=yes
# TODO: check that copyfrom was used


# Re-use the inode number.
mv $fn1-22 $fn1-23
# A simple move would find the identical MD5, so change the data.
echo XX >> $fn1-23
mv di1 di2
# A file and a directory may not be associated.
# But how could we (reliable) get a directory with the same inode# as a 
# (just) removed file? The only way I see is using some hex-editor!
# TODO

$BINdflt copyfrom-detect > $log
if [[ $(echo `sort < $log`) == "di2 file-1-23 inode:di1 inode:file-1-22" ]]
then
  $SUCCESS "Moved, changed file found."
else
	cat $log
  $ERROR "inode check didn't work."
fi


# Get some unique value
echo $RANDOM-$RANDOM-$RANDOM-$RANDOM > $fn1-a
$BINq ci -m a -o delay=yes
# TODO: check that copyfrom was used


# check that files not given as arguments can be a source, too.
# files *not* listed should not be found.
function arg_check
{
  num=$1
	arg=$2
  src=${3:-$fn1-a}
  dst=${4:-di2/asf}
  msg=${5:-Argument usage check ($1)}
	$BINdflt copyfrom-detect $arg > $log
  if [[ $(echo `sort < $log`) == "$dst md5:$src" ]]
  then
    $SUCCESS "$msg"
  else
    echo "--- Expected:"
    echo "$dst"
    echo "  md5:$src"
		echo "--- Got:"
  	cat $log
    $ERROR "$msg"
  fi
}

# The names of the directory and the file must be alphabetically before
# "md5", so that the sort check above works.
cat $fn1-a > di2/asf
cat $fn1-a > ignoreme
arg_check 1 di2 "$WC/$fn1-a" 
arg_check 2 di2/asf "$WC/$fn1-a" 

arg_check 3 di2/. "$WC/$fn1-a" "di2/./asf"
cd di2
arg_check 4 . "$WC/$fn1-a" "./asf"
arg_check 5 "" "$WC/$fn1-a" "asf"
cd ..


cd $WC
# Test that a copied entry has the correct md5 set, if it gets changed 
# before commit.
$BINq cp $fn1-a di2/asf
date >> di2/asf
echo $RANDOM $$ >> di2/asf
$BINq ci -m "copy" -o delay=yes # -d > $LOGDIR/043.ci 

cat di2/asf > 6uhtr
arg_check 6 6uhtr "$WC/di2/asf" 6uhtr "Committing copied with change"


# Test for MD5 set on a straight copy - no changes transmitted.
# Make "source" file unique
echo $RANDOM $$ >> 6uhtr
$BINdflt cp di2/asf 6uhtr
$BINq ci -m "copy" -o delay=yes # -d > $LOGDIR/043.ci 
cat 6uhtr > bthtrgb
arg_check 7 bthtrgb "$WC/6uhtr" bthtrgb "Committing copied without change"
$BINq cp 6uhtr bthtrgb