Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions connstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package main

import (
"fmt"
"maps"
"net/url"
"sort"
"strings"
Expand Down Expand Up @@ -85,10 +86,7 @@ func (c *ConnInfo) Copy() *ConnInfo {
Kind: c.Kind,
Infos: make(map[string]string, len(c.Infos)),
}

for k, v := range c.Infos {
newC.Infos[k] = v
}
maps.Copy(newC.Infos, c.Infos)

return &newC
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/orgrim/pg_back

go 1.23.0
go 1.24.0

toolchain go1.24.1

Expand Down
6 changes: 3 additions & 3 deletions hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ package main
import (
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"path/filepath"
Expand All @@ -50,7 +50,7 @@ func TestChecksumFile(t *testing.T) {

// create a temporary directory to store a test file to
// checksum with the different algorithm relatively
dir, err := ioutil.TempDir("", "test_checksum_file")
dir, err := os.MkdirTemp("", "test_checksum_file")
if err != nil {
t.Fatal("could not create tempdir:", err)
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestChecksumFile(t *testing.T) {

// bad files
var e *os.PathError
l.logger.SetOutput(ioutil.Discard)
l.logger.SetOutput(io.Discard)
if _, err := checksumFile("", 0o700, "sha1"); !errors.As(err, &e) {
t.Errorf("expected an *os.PathError, got %q\n", err)
}
Expand Down
7 changes: 4 additions & 3 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ package main

import (
"fmt"
"github.com/anmitsu/go-shlex"
"os"
"os/exec"
"strings"

"github.com/anmitsu/go-shlex"
)

func hookCommand(cmd string, logPrefix string) error {
Expand All @@ -51,15 +52,15 @@ func hookCommand(cmd string, logPrefix string) error {
c := exec.Command(prog, args...)
stdoutStderr, err := c.CombinedOutput()
if err != nil {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Errorln(logPrefix, line)
}
}
return err
}
if len(stdoutStderr) > 0 {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Infoln(logPrefix, line)
}
Expand Down
8 changes: 4 additions & 4 deletions legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ package main

import (
"fmt"
"github.com/anmitsu/go-shlex"
"io"
"io/ioutil"
"os"
"strings"

"github.com/anmitsu/go-shlex"
)

// Read the input file and return all lines that look like legacy configuration
// options
func readLegacyConf(f io.Reader) ([]string, error) {
var lines []string

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return lines, fmt.Errorf("could not read file: %w", err)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func convertLegacyConf(oldConf []string) string {
case "PGBK_DBLIST", "PGBK_EXCLUDE":
// The separator for lists of databases now the comma
dbs := make([]string, 0)
for _, d := range strings.Split(strings.Trim(value, "'\""), " ") {
for d := range strings.SplitSeq(strings.Trim(value, "'\""), " ") {
if len(d) > 0 {
dbs = append(dbs, d)
}
Expand Down
3 changes: 2 additions & 1 deletion legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ package main
import (
"bytes"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"testing"
)

func TestReadLegacyConf(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//go:build !windows
// +build !windows

package main
Expand Down
5 changes: 2 additions & 3 deletions lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package main

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand All @@ -36,7 +35,7 @@ import (

func TestLockPath(t *testing.T) {
// Work from a tempdir
dir, err := ioutil.TempDir("", "test_lockpath")
dir, err := os.MkdirTemp("", "test_lockpath")
if err != nil {
t.Fatal("could not create tempdir:", err)
}
Expand Down Expand Up @@ -83,7 +82,7 @@ func TestLockPath(t *testing.T) {
}

func TestUnlockPath(t *testing.T) {
f, err := ioutil.TempFile("", "test_unlockpath")
f, err := os.CreateTemp("", "test_unlockpath")
if err != nil {
t.Fatal("could not create tempfile")
}
Expand Down
1 change: 1 addition & 0 deletions lock_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//go:build windows
// +build windows

package main
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func (d *dump) dump(fc chan<- sumFileJob) error {
l.Verboseln("running:", pgDumpCmd)
stdoutStderr, err := pgDumpCmd.CombinedOutput()
if err != nil {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Errorf("[%s] %s\n", dbname, line)
}
Expand All @@ -718,7 +718,7 @@ func (d *dump) dump(fc chan<- sumFileJob) error {
return err
}
if len(stdoutStderr) > 0 {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Infof("[%s] %s\n", dbname, line)
}
Expand Down Expand Up @@ -979,15 +979,15 @@ func dumpGlobals(dir string, mode int, timeFormat string, withRolePasswords bool
l.Verboseln("running:", pgDumpallCmd)
stdoutStderr, err := pgDumpallCmd.CombinedOutput()
if err != nil {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Errorln(line)
}
}
return err
}
if len(stdoutStderr) > 0 {
for _, line := range strings.Split(string(stdoutStderr), "\n") {
for line := range strings.SplitSeq(string(stdoutStderr), "\n") {
if line != "" {
l.Infoln(line)
}
Expand Down
7 changes: 3 additions & 4 deletions purge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand All @@ -38,7 +37,7 @@ import (
// func purgeDumps(directory string, dbname string, keep int, limit time.Time) error
func TestPurgeDumps(t *testing.T) {
// work in a tempdir
dir, err := ioutil.TempDir("", "test_purge_dumps")
dir, err := os.MkdirTemp("", "test_purge_dumps")
if err != nil {
t.Fatal("could not create tempdir:", err)
}
Expand Down Expand Up @@ -81,7 +80,7 @@ func TestPurgeDumps(t *testing.T) {
// file without write perms
if runtime.GOOS != "windows" {
tf = formatDumpPath(wd, time.RFC3339, "dump", "db", time.Now().Add(-time.Hour), 0)
ioutil.WriteFile(tf, []byte("truc\n"), 0644)
os.WriteFile(tf, []byte("truc\n"), 0644)
os.Chmod(filepath.Dir(tf), 0555)

err = purgeDumps(wd, "db", 0, time.Now())
Expand Down Expand Up @@ -139,7 +138,7 @@ func TestPurgeDumps(t *testing.T) {
for i := 1; i <= 3; i++ {
when := time.Now().Add(-time.Hour * time.Duration(i))
tf = formatDumpPath(wd, st.format, "dump", "db", when, 0)
ioutil.WriteFile(tf, []byte("truc\n"), 0644)
os.WriteFile(tf, []byte("truc\n"), 0644)
os.Chtimes(tf, when, when)
}

Expand Down
5 changes: 3 additions & 2 deletions sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/jackc/pgtype"
_ "github.com/jackc/pgx/v4/stdlib"
"strings"
"time"

"github.com/jackc/pgtype"
_ "github.com/jackc/pgx/v4/stdlib"
)

type pg struct {
Expand Down
5 changes: 3 additions & 2 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ package main

import (
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"os"
"regexp"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)

var (
Expand Down