rsyncd

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: BSD-3-Clause Imports: 20 Imported by: 2

Documentation

Overview

Package rsyncd implements an rsync server (only), but note that gokrazy/rsync contains a native Go rsync implementation that supports sending and receiving files as client or server, compatible with the original tridge rsync (from the samba project) or openrsync (used on OpenBSD and macOS 15+).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn added in v0.2.4

type Conn struct {
	// contains filtered or unexported fields
}

func NewConnection added in v0.2.4

func NewConnection(r io.ReadCloser, w io.WriteCloser, name string) *Conn

type Module

type Module struct {
	Name     string   `toml:"name"`
	Path     string   `toml:"path"` // If empty, FS must be non-nil
	FS       fs.FS    `toml:"-"`    // If set, serve from this instead of Path
	ACL      []string `toml:"acl"`
	Writable bool     `toml:"writable"` // Must be false if FS is set
}

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option specifies the server options.

func DontRestrict added in v0.2.7

func DontRestrict() Option

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger specifies the logger to use for the server. It also sets the global logger used by the rsync package.

func WithStderr added in v0.2.3

func WithStderr(stderr io.WriteCloser) Option

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(modules []Module, opts ...Option) (*Server, error)
Example
package main

import (
	"context"
	"log"
	"net"

	"github.com/gokrazy/rsync/rsyncd"
)

func main() {
	listener, err := net.Listen("tcp", "localhost:8873")
	if err != nil {
		log.Fatal(err)
	}

	rsyncServer, err := rsyncd.NewServer([]rsyncd.Module{
		{
			Name: "music",
			Path: "/home/bob/Music",
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	if err := rsyncServer.Serve(context.Background(), listener); err != nil {
		log.Fatal(err)
	}
}
Example (FsFS)

ExampleNewServer_fsFS shows how to serve an rsync module backed by an fs.FS instead of a filesystem path. This allows serving files from in-memory filesystems, embedded files, or any other fs.FS implementation.

package main

import (
	"context"
	"log"
	"net"
	"testing/fstest"

	"github.com/gokrazy/rsync/rsyncd"
)

func main() {
	// Create an in-memory filesystem using testing/fstest.
	// Any fs.FS implementation works (embed.FS, zip archives, etc.)
	memfs := fstest.MapFS{
		"hello.txt": &fstest.MapFile{
			Data: []byte("Hello from fs.FS!"),
			Mode: 0o644,
		},
		"readme.md": &fstest.MapFile{
			Data: []byte("# Welcome\nThis is served from memory."),
			Mode: 0o644,
		},
	}

	listener, err := net.Listen("tcp", "localhost:8873")
	if err != nil {
		log.Fatal(err)
	}

	rsyncServer, err := rsyncd.NewServer([]rsyncd.Module{
		{
			Name: "inmemory",
			FS:   memfs,
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("listening; now run: rsync -av rsync://%s/inmemory", listener.Addr())

	if err := rsyncServer.Serve(context.Background(), listener); err != nil {
		log.Fatal(err)
	}
}

func (*Server) HandleConnArgs added in v0.2.5

func (s *Server) HandleConnArgs(ctx context.Context, conn *Conn, module *Module, args []string) error

func (*Server) HandleDaemonConn

func (s *Server) HandleDaemonConn(ctx context.Context, conn *Conn) (err error)

FIXME: context cancellation not yet implemented

func (*Server) InternalHandleConn added in v0.2.5

func (s *Server) InternalHandleConn(ctx context.Context, conn *Conn, module *Module, pc *rsyncopts.Context) error

This method is only exported until we refactor; use HandleConnArgs() instead

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL