Debian Codegraph @

rsynccmd/rsynccmd.go

raw symbols SCIP
1 // Package rsynccmd provides a command-like interface to gokrazy/rsync, which
2 // contains a native Go rsync implementation that supports sending and receiving
3 // files as client or server, compatible with the original tridge rsync (from
4 // the samba project) or openrsync (used on OpenBSD and macOS 15+).
5 //
6 // This interface allows you to replace calls to an external rsync program, like:
7 //
8 // rsync -a rsync://share01/dataset /tmp/dataset
9 //
10 // …with calls into Go code running in the same process (no dependency on an
11 // external rsync program!):
12 //
13 // cmd := rsynccmd.Command("rsync", "-a", "rsync://share01/dataset", "/tmp/dataset")
14 // cmd.Stdout = os.Stdout
15 // cmd.Stderr = os.Stderr
16 // if _, err := cmd.Run(context.Background()); err != nil {
17 // return fmt.Errorf("%v: %v", cmd.Args, err)
18 // }
19 package rsynccmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/
20
21 import (
22 "contextscip-go gomod github.com/golang/go/src go1.25.0 context/"
23 "ioscip-go gomod github.com/golang/go/src go1.25.0 io/"
24 "netscip-go gomod github.com/golang/go/src go1.25.0 net/"
25
26 "github.com/gokrazy/rsync/internal/maincmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/maincmd`/"
27 "github.com/gokrazy/rsync/internal/rsyncosscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/"
28 "github.com/gokrazy/rsync/internal/rsyncstatsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncstats`/"
29 )
30
31 // Cmd represents an rsync invocation being prepared or run.
32 type Cmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd# struct {
33 Argsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Args. []string
34 Stdinscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stdin. ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ReadCloserscip-go gomod github.com/golang/go/src go1.25.0 io/ReadCloser#
35 Stdoutscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stdout. ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteCloserscip-go gomod github.com/golang/go/src go1.25.0 io/WriteCloser#
36 Stderrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stderr. ioscip-go gomod github.com/golang/go/src go1.25.0 io/.WriteCloserscip-go gomod github.com/golang/go/src go1.25.0 io/WriteCloser#
37 DontRestrictscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#DontRestrict. bool
38
39 DialContextscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#DialContext. func(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#, network, addr string) (netscip-go gomod github.com/golang/go/src go1.25.0 net/.Connscip-go gomod github.com/golang/go/src go1.25.0 net/Conn#, error)
40 }
41
42 // Command returns the [Cmd] struct to execute rsync with the given arguments.
43 //
44 // The name parameter is ignored and only specified for symmetry with
45 // os/exec.Command.
46 func Commandscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Command().(name string, arg ...string) *Cmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd# {
47 return &Cmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#{
48 Argsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Args.: append([]string{name}, arg...),
49 }
50 }
51
52 // Result contains information about the transfer.
53 type Resultscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Result# struct {
54 Statsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Result#Stats. *rsyncstatsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncstats`/.TransferStatsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncstats`/TransferStats#
55 }
56
57 // Run starts the specified rsync invocation.
58 func (c *Cmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#) Runscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Run().(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#) (*Resultscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Result#, error) {
59 osenv := &rsyncosscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/.Envscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#{
60 Stdinscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#Stdin.: c.Stdinscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stdin.,
61 Stdoutscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#Stdout.: c.Stdoutscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stdout.,
62 Stderrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#Stderr.: c.Stderrscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Stderr.,
63 DontRestrictscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#DontRestrict.: c.DontRestrictscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#DontRestrict.,
64 DialContextscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/rsyncos`/Env#DialContext.: c.DialContextscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#DialContext.,
65 }
66 stats, err := maincmdscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/maincmd`/.Mainscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/internal/maincmd`/Main().(ctx, osenv, c.Argsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Cmd#Args., nil)
67 if err != nil {
68 return nil, err
69 }
70 return &Resultscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Result#{Statsscip-go gomod github.com/gokrazy/rsync . `github.com/gokrazy/rsync/rsynccmd`/Result#Stats.: stats}, nil
71 }