| 1 | package rsyncscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/" |
| 5 | |
| 6 | "github.com/gokrazy/rsync/internal/rsyncwirescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/" |
| 7 | ) |
| 8 | |
| 9 | // rsync/rsync.h:struct sum_buf |
| 10 | type SumBufscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf# struct { |
| 11 | Offsetscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Offset. int64 |
| 12 | Lenscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Len. int64 |
| 13 | Indexscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Index. int32 |
| 14 | Sum1scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Sum1. uint32 |
| 15 | Sum2scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf#Sum2. [16]byte |
| 16 | } |
| 17 | |
| 18 | // TODO: remove connection.go:sumHead in favor of this type |
| 19 | type SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead# struct { |
| 20 | // “number of blocks” (openrsync) |
| 21 | // “how many chunks” (rsync) |
| 22 | ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount. int32 |
| 23 | |
| 24 | // “block length in the file” (openrsync) |
| 25 | // maximum (1 << 29) for older rsync, (1 << 17) for newer |
| 26 | BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength. int32 |
| 27 | |
| 28 | // “long checksum length” (openrsync) |
| 29 | ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength. int32 |
| 30 | |
| 31 | // “terminal (remainder) block length” (openrsync) |
| 32 | // RemainderLength is flength % BlockLength |
| 33 | RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength. int32 |
| 34 | |
| 35 | Sumsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#Sums. []SumBufscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumBuf# |
| 36 | } |
| 37 | |
| 38 | func (sh *SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#) ReadFromscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ReadFrom().(c *rsyncwirescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#) error { |
| 39 | // TODO(protocol>=30): update maxBlockLen |
| 40 | const maxBlockLen = 1 << 29 // see rsync.h:OLD_MAX_BLOCK_SIZE |
| 41 | |
| 42 | var err error |
| 43 | sh.ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount., err = c.ReadInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#ReadInt32().() |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | if sh.ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount. < 0 { |
| 48 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("invalid checksum count %d", sh.ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount.) |
| 49 | } |
| 50 | |
| 51 | sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength., err = c.ReadInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#ReadInt32().() |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | if sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength. < 0 || sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength. > maxBlockLen { |
| 56 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("invalid block length %d", sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.) |
| 57 | } |
| 58 | |
| 59 | sh.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength., err = c.ReadInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#ReadInt32().() |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | // TODO(protocol>=27): update max sh.ChecksumLength check |
| 64 | if sh.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength. < 0 || sh.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength. > 16 { |
| 65 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("invalid checksum length %d", sh.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength.) |
| 66 | } |
| 67 | |
| 68 | sh.RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength., err = c.ReadInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#ReadInt32().() |
| 69 | if err != nil { |
| 70 | return err |
| 71 | } |
| 72 | if sh.RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength. < 0 || sh.RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength. > sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength. { |
| 73 | return fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Errorf().("invalid remainder length %d", sh.RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength.) |
| 74 | } |
| 75 | |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | func (sh *SumHeadscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#) WriteToscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#WriteTo().(c *rsyncwirescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/.Connscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#) error { |
| 80 | var buf rsyncwirescip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/.Bufferscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer# |
| 81 | buf.WriteInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer#WriteInt32().(sh.ChecksumCountscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumCount.) |
| 82 | buf.WriteInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer#WriteInt32().(sh.BlockLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#BlockLength.) |
| 83 | buf.WriteInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer#WriteInt32().(sh.ChecksumLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#ChecksumLength.) |
| 84 | buf.WriteInt32scip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer#WriteInt32().(sh.RemainderLengthscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync`/SumHead#RemainderLength.) |
| 85 | return c.WriteStringscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Conn#WriteString().(buf.Stringscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncwire`/Buffer#String().()) |
| 86 | } |