Skip to content

Commit

Permalink
fix: several minor quality issues (#23667)
Browse files Browse the repository at this point in the history
* fix: invalid assign to nil pointer

* fix: close some files that were being left open

* fix: lint
  • Loading branch information
jeffreyssmith2nd authored Aug 23, 2022
1 parent 785a465 commit daaf866
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion http/notification_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func decodeNotificationRuleFilter(ctx context.Context, r *http.Request) (*influx
}
f.OrgID = orgID
} else if orgNameStr := q.Get("org"); orgNameStr != "" {
*f.Organization = orgNameStr
f.Organization = &orgNameStr
}

for _, tag := range q["tag"] {
Expand Down
14 changes: 10 additions & 4 deletions sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"path/filepath"
"sync"

errors2 "github.com/influxdata/influxdb/v2/pkg/errors"

"github.com/influxdata/influxdb/v2/kit/tracing"
"github.com/influxdata/influxdb/v2/pkg/fs"
sqliteMigrations "github.com/influxdata/influxdb/v2/sqlite/migrations"
Expand Down Expand Up @@ -120,7 +122,7 @@ func (s *SqlStore) Flush(ctx context.Context) {
// is the resulting backup. The underlying sqlite connection is needed for both
// SOURCE and DESTINATION databases to use the sqlite backup API made available by the
// go-sqlite3 driver.
func (s *SqlStore) BackupSqlStore(ctx context.Context, w io.Writer) error {
func (s *SqlStore) BackupSqlStore(ctx context.Context, w io.Writer) (rErr error) {
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

Expand All @@ -136,6 +138,7 @@ func (s *SqlStore) BackupSqlStore(ctx context.Context, w io.Writer) error {
if err != nil {
return err
}
defer errors2.Capture(&rErr, dest.Close)

if err := backup(ctx, dest, s); err != nil {
return err
Expand Down Expand Up @@ -211,7 +214,7 @@ func sqliteFromSqlConn(c *sql.Conn) (*sqlite3.SQLiteConn, error) {
}

// RestoreSqlStore replaces the underlying database with the data from r.
func (s *SqlStore) RestoreSqlStore(ctx context.Context, r io.Reader) error {
func (s *SqlStore) RestoreSqlStore(ctx context.Context, r io.Reader) (rErr error) {
tempDir, err := os.MkdirTemp("", "")
if err != nil {
return err
Expand All @@ -224,13 +227,16 @@ func (s *SqlStore) RestoreSqlStore(ctx context.Context, r io.Reader) error {
if err != nil {
return err
}
defer errors2.Capture(&rErr, f.Close)

// Copy the contents of r to the temporary file
if _, err := io.Copy(f, r); err != nil {
return err
} else if err := f.Sync(); err != nil {
}
if err := f.Sync(); err != nil {
return err
} else if err := f.Close(); err != nil {
}
if err := f.Close(); err != nil {
return err
}

Expand Down

0 comments on commit daaf866

Please sign in to comment.