Skip to content

Commit

Permalink
modernize code for Go 1.24
Browse files Browse the repository at this point in the history
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -test -fix ./...
  • Loading branch information
stapelberg committed Feb 21, 2025
1 parent 384848f commit 4bc6396
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type fakeLogger struct {

var _ log.Logger = (*fakeLogger)(nil)

func (f *fakeLogger) Printf(msg string, a ...interface{}) {
func (f *fakeLogger) Printf(msg string, a ...any) {
fmt.Fprintf(f.out, msg, a...)
}

Expand Down
5 changes: 1 addition & 4 deletions internal/receiver/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ func (rt *Transfer) generateAndSendSums(in *os.File, fileLen int64) error {
buf := make([]byte, int(sh.BlockLength))
remaining := fileLen
for i := int32(0); i < sh.ChecksumCount; i++ {
n1 := int64(sh.BlockLength)
if n1 > remaining {
n1 = remaining
}
n1 := min(int64(sh.BlockLength), remaining)
b := buf[:n1]
if _, err := io.ReadFull(in, b); err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions internal/rsynccommon/rsynccommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ func SumSizesSqroot(contentLen int64) rsync.SumHead {
// For reasons unknown, the square root result is rounded up to the nearest multiple of eight.

// TODO: round this
blockLength := int32(math.Sqrt(float64(contentLen)))
if blockLength < blockSize {
blockLength = blockSize
}
blockLength := max(int32(math.Sqrt(float64(contentLen))), blockSize)

// * The checksum size is determined according to:
// * blocksum_bits = BLOCKSUM_EXP + 2*log2(file_len) - log2(block_len)
Expand Down
4 changes: 2 additions & 2 deletions internal/rsyncopts/rsyncopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ var infoWords = [...]output{

func parseOutputWords(words []output, levels []uint16, str string, prio priority) {
Level:
for _, s := range strings.Split(str, ",") {
for s := range strings.SplitSeq(str, ",") {
if strings.TrimSpace(s) == "" {
continue
}
Expand All @@ -323,7 +323,7 @@ Level:
case "all":
all = true
}
for j := 0; j < len(words); j++ {
for j := range words {
word := words[j]
if strings.ToLower(word.name) == trimmed || all {
levels[j] = uint16(lev)
Expand Down
5 changes: 1 addition & 4 deletions internal/sender/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,7 @@ Outer:

// Update the rolling checksum by removing the oldest byte (update[0])
// and adding the newest byte (update[k]).
backup := offset - st.lastMatch
if backup < 0 {
backup = 0
}
backup := max(offset-st.lastMatch, 0)

more := offset+int64(k) < fi.Size()
mmore := int64(0)
Expand Down
2 changes: 1 addition & 1 deletion rsyncd/rsyncd.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (s *Server) HandleDaemonConn(ctx context.Context, conn io.ReadWriter, remot
// Switch to multiplexing protocol, but only for server-side transmissions.
// Transmissions received from the client are not multiplexed.
mpx := &rsyncwire.MultiplexWriter{Writer: c.Writer}
mpx.WriteMsg(rsyncwire.MsgError, []byte(fmt.Sprintf("gokr-rsync [sender]: %v\n", err)))
mpx.WriteMsg(rsyncwire.MsgError, fmt.Appendf(nil, "gokr-rsync [sender]: %v\n", err))

return err
}
Expand Down

0 comments on commit 4bc6396

Please sign in to comment.