-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathnocopyreadall.bash
More file actions
executable file
·148 lines (126 loc) · 4.53 KB
/
Copy pathnocopyreadall.bash
File metadata and controls
executable file
·148 lines (126 loc) · 4.53 KB
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
#!/bin/bash
set -euo pipefail
#
# This script ensures that non-testing code never uses io.ReadAll and io.Copy and
# prefers their netxlite counterparts who also take a context argument.
#
# See https://github.com/ooni/probe/issues/1609.
#
exitcode=0
for file in $(find . -type f -name \*.go); do
if [ "$file" = "./internal/netemx/ooapi_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/netxlite/iox.go" ]; then
# We're allowed to use ReadAll and Copy in this file to
# implement safer wrappers for these functions.
continue
fi
if [ "$file" = "./internal/must/must_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file to
# avoid depending on netxlite, given that netxlite's test
# suite already depends on must.
continue
fi
if [ "$file" = "./internal/shellx/shellx.go" ]; then
# We're allowed to use ReadAll and Copy in this file to
# avoid depending on netxlite, given that netxlite's does
# not compile with go1.18 due to the quic dependency.
continue
fi
if [ "$file" = "./internal/shellx/shellx_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file to
# avoid depending on netxlite, given that netxlite's does
# not compile with go1.18 due to the quic dependency.
continue
fi
if [ "$file" = "./internal/testingsocks5/request.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/dnsoverhttps.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/dnsoverhttps_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/httpproxy.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/httptestx.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/httptestx_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/oonibackendwithlogin.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/oonibackendwithlogin_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/oonicollector.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/oonicollector_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/tlssniproxy.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/tlsx_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./internal/testingx/geoip_test.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# it's code that we only use for testing purposes.
continue
fi
if [ "$file" = "./pkg/gobash/version.go" ]; then
# We're allowed to use ReadAll and Copy in this file because
# this code is only used by the build system
continue
fi
if grep -q 'io\.ReadAll' $file; then
echo "in $file: do not use io.ReadAll, use netxlite.ReadAllContext" 1>&2
exitcode=1
fi
if grep -q 'ioutil\.ReadAll' $file; then
echo "in $file: do not use ioutil.ReadAll, use netxlite.ReadAllContext" 1>&2
exitcode=1
fi
if grep -q 'io\.Copy' $file; then
echo "in $file: do not use io.Copy, use netxlite.CopyContext" 1>&2
exitcode=1
fi
if grep -q 'ioutil\.Copy' $file; then
echo "in $file: do not use ioutil.Copy, use netxlite.CopyContext" 1>&2
exitcode=1
fi
done
exit $exitcode