Skip to content

Commit 420dc66

Browse files
author
Christian Brauner
committed
upgrade: add ifdefines
This makes it possible to correctly link against the system sqlite. Also, don't use defers with log.Fatal() since they won't be run on exit. Signed-off-by: Christian Brauner <[email protected]>
1 parent f6e7921 commit 420dc66

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tool/upgrade.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,21 @@ func main() {
3737
if err != nil {
3838
log.Fatal(err)
3939
}
40-
defer resp.Body.Close()
4140

4241
b, err := ioutil.ReadAll(resp.Body)
4342
if err != nil {
43+
resp.Body.Close()
4444
log.Fatal(err)
4545
}
4646

4747
fmt.Printf("extracting %v\n", path.Base(url))
4848
r, err := zip.NewReader(bytes.NewReader(b), resp.ContentLength)
4949
if err != nil {
50+
resp.Body.Close()
5051
log.Fatal(err)
5152
}
53+
resp.Body.Close()
54+
5255
for _, zf := range r.File {
5356
var f *os.File
5457
switch path.Base(zf.Name) {
@@ -68,11 +71,27 @@ func main() {
6871
if err != nil {
6972
log.Fatal(err)
7073
}
74+
75+
_, err = io.WriteString(f, "#ifndef USE_LIBSQLITE3\n")
76+
if err != nil {
77+
zr.Close()
78+
f.Close()
79+
log.Fatal(err)
80+
}
7181
_, err = io.Copy(f, zr)
72-
f.Close()
7382
if err != nil {
83+
zr.Close()
84+
f.Close()
7485
log.Fatal(err)
7586
}
87+
_, err = io.WriteString(f, "#else // USE_LIBSQLITE3\n // If users really want to link against the system sqlite3 we\n// need to make this file a noop.\n #endif")
88+
if err != nil {
89+
zr.Close()
90+
f.Close()
91+
log.Fatal(err)
92+
}
93+
zr.Close()
94+
f.Close()
7695
fmt.Printf("extracted %v\n", filepath.Base(f.Name()))
7796
}
7897
}

0 commit comments

Comments
 (0)