Commit 7e9e8a9d authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/zodbtools: *: Don't forget to close storage on program exit

Implement "TODO defer stor.Close()" that was sitting there in every subcommand.
parent 949d42da
// Copyright (C) 2017-2019 Nexedi SA and Contributors.
// Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -125,25 +125,37 @@ func catobjMain(argv []string) {
}
ctx := context.Background()
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
prog.Fatal(err)
}
// TODO defer stor.Close()
catobj := func(xid zodb.Xid) error {
if raw {
return Catobj(ctx, os.Stdout, stor, xid)
} else {
return Dumpobj(ctx, os.Stdout, stor, xid, hashOnly)
err := func() (err error) {
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
return err
}
defer func() {
err2 := stor.Close()
if err == nil {
err = err2
}
}()
catobj := func(xid zodb.Xid) error {
if raw {
return Catobj(ctx, os.Stdout, stor, xid)
} else {
return Dumpobj(ctx, os.Stdout, stor, xid, hashOnly)
}
}
}
for _, xid := range xidv {
err = catobj(xid)
if err != nil {
prog.Fatal(err)
for _, xid := range xidv {
err = catobj(xid)
if err != nil {
return err
}
}
return nil
}()
if err != nil {
prog.Fatal(err)
}
}
......@@ -256,20 +256,27 @@ func dumpMain(argv []string) {
tidRange = argv[1]
}
tidMin, tidMax, err := zodb.ParseTidRange(tidRange)
if err != nil {
prog.Fatal(err)
}
ctx := context.Background()
err := func() (err error) {
tidMin, tidMax, err := zodb.ParseTidRange(tidRange)
if err != nil {
return err
}
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
prog.Fatal(err)
}
// TODO defer stor.Close()
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
return err
}
defer func() {
err2 := stor.Close()
if err == nil {
err = err2
}
}()
return Dump(ctx, os.Stdout, stor, tidMin, tidMax, hashOnly)
}()
err = Dump(ctx, os.Stdout, stor, tidMin, tidMax, hashOnly)
if err != nil {
prog.Fatal(err)
}
......
// Copyright (C) 2017-2019 Nexedi SA and Contributors.
// Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -127,14 +127,21 @@ func infoMain(argv []string) {
zurl := argv[0]
ctx := context.Background()
err := func() (err error) {
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
return err
}
defer func() {
err2 := stor.Close()
if err == nil {
err = err2
}
}()
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
prog.Fatal(err)
}
// TODO defer stor.Close()
return Info(ctx, os.Stdout, stor, argv[1:])
}()
err = Info(ctx, os.Stdout, stor, argv[1:])
if err != nil {
prog.Fatal(err)
}
......
// Copyright (C) 2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
// Copyright (C) 2019-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
......@@ -153,14 +153,21 @@ func watchMain(argv []string) {
zurl := argv[0]
ctx := context.Background()
err := func() (err error) {
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
return err
}
defer func() {
err2 := stor.Close()
if err == nil {
err = err2
}
}()
stor, err := zodb.Open(ctx, zurl, &zodb.OpenOptions{ReadOnly: true})
if err != nil {
prog.Fatal(err)
}
// TODO defer stor.Close()
return Watch(ctx, stor, os.Stdout, verbose)
}()
err = Watch(ctx, stor, os.Stdout, verbose)
if err != nil {
prog.Fatal(err)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment