rsync

package
v0.2.1-0...-f046be3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	END_FLAG      = 0
	TOKEN_LONG    = 0x20
	TOKENRUN_LONG = 0x21
	DEFLATED_DATA = 0x40
	TOKEN_REL     = 0x80
	TOKENRUN_REL  = 0xc0
)
View Source
const (
	RSYNC_VERSION = "@RSYNCD: 27.0\n"
	RSYNCD_OK     = "@RSYNCD: OK"
	RSYNC_EXIT    = "@RSYNCD: EXIT"

	K = 1 << 10
	M = 1 << 20
	G = 1 << 30

	MAXPATHLEN    = 1024
	INDEX_END     = int32(-1)
	EXCLUSION_END = int32(0)
	END1          = '\n'
	END2          = '\x00'
	PHASE_END     = int32(-1)

	// ARGUMENTS
	ARG_SERVER       = "--server"
	ARG_SENDER       = "--sender"
	ARG_SYMLINK      = "-l"
	ARG_RECURSIVE    = "-r"
	ARG_PERMS        = "-p"
	SAMPLE_ARGS      = "--server\n--sender\n-l\n-p\n-r\n-t\n.\n"
	SAMPLE_LIST_ARGS = "--server\n--sender\n--list-only\n-l\n-p\n-r\n-t\n.\n"

	// For Multiplex(1 byte)
	MUX_BASE       = 7
	MSG_DATA       = 0
	MSG_ERROR_XFER = 1
	MSG_INFO       = 2
	MSG_ERROR      = 3
	MSG_WARNING    = 4
	MSG_IO_ERROR   = 22
	MSG_NOOP       = 42
	MSG_SUCCESS    = 100
	MSG_DELETED    = 101
	MSG_NO_SEND    = 102

	// For FILE LIST(1 byte)
	FLIST_END       = 0x00
	FLIST_TOP_LEVEL = 0x01 /* needed for remote --delete */
	FLIST_MODE_SAME = 0x02 /* mode is repeat */
	FLIST_RDEV_SAME = 0x04 /* rdev is repeat */
	FLIST_UID_SAME  = 0x08 /* uid is repeat */
	FLIST_GID_SAME  = 0x10 /* gid is repeat */
	FLIST_NAME_SAME = 0x20 /* name is repeat */
	FLIST_NAME_LONG = 0x40 /* name >255 bytes */
	FLIST_TIME_SAME = 0x80 /* time is repeat */

	// File type
	S_IFMT   = 0170000 /* Type of file */
	S_IFREG  = 0100000 /* Regular file.  */
	S_IFDIR  = 0040000 /* Directory.  */
	S_IFLNK  = 0120000 /* Symbolic link.  */
	S_IFCHR  = 0020000 /* Character device.  */
	S_IFBLK  = 0060000 /* Block device.  */
	S_IFIFO  = 0010000 /* FIFO.  */
	S_IFSOCK = 0140000 /* Socket.  */
)

Variables

This section is empty.

Functions

func NewflatedtokenReader

func NewflatedtokenReader(reader Conn) *flatedtokenReader

func SplitURI

func SplitURI(uri string) (string, string, string, error)

For rsync

func SplitURIS

func SplitURIS(uri string) (string, int, string, string, error)

func TrimPrepath

func TrimPrepath(prepath string) string

The path always has a trailing slash appended

Types

type Attribs

type Attribs struct {
	Sender     bool // --sender
	Server     bool // --server
	Recursive  bool // -r
	DryRun     bool // -n
	HasModTime bool // -t
	HasPerms   bool // -p
	HasLinks   bool // -l
	HasGID     bool // -g
	HasUID     bool // -u

}

func (*Attribs) Marshal

func (a *Attribs) Marshal() []byte

type Conn

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

io.ReadWriteCloser This struct has two main attributes, both of them can be used for a plain socket or an SSH

func (*Conn) Close

func (conn *Conn) Close() error

TODO: If both writer and reader are based on a same Connection (socket, SSH), how to close them twice?

func (*Conn) Read

func (conn *Conn) Read(p []byte) (n int, err error)

func (*Conn) ReadByte

func (conn *Conn) ReadByte() (byte, error)
Encoding: little endian

size of: int: 4, long: 8, varint: 4 or 8

func (*Conn) ReadInt

func (conn *Conn) ReadInt() (int32, error)

func (*Conn) ReadLong

func (conn *Conn) ReadLong() (int64, error)

func (*Conn) ReadShort

func (conn *Conn) ReadShort() (int16, error)

func (*Conn) ReadVarint

func (conn *Conn) ReadVarint() (int64, error)

func (*Conn) Write

func (conn *Conn) Write(p []byte) (n int, err error)

func (*Conn) WriteByte

func (conn *Conn) WriteByte(data byte) error

func (*Conn) WriteInt

func (conn *Conn) WriteInt(data int32) error

func (*Conn) WriteLong

func (conn *Conn) WriteLong(data int64) error

func (*Conn) WriteShort

func (conn *Conn) WriteShort(data int16) error

type Exclusion

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

Filter List

func (*Exclusion) Add

func (e *Exclusion) Add(pattern string)

func (*Exclusion) Match

func (e *Exclusion) Match(name string) (matched bool, err error)

func (*Exclusion) SendExlusion

func (e *Exclusion) SendExlusion(conn Conn) error

This is only called by the client

type FS

type FS interface {
	Put(fileName string, content io.Reader, fileSize int64, metadata FileMetadata) (written int64, err error)
	//Get(fileName string, metadata FileMetadata) (File, error)
	GetURI(path string) (string, error)
	Delete(fileName string, mode FileMode) error
	List() (FileList, error)
}

File System: need to handle all type of files: regular, folder, symlink, etc

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}

Interface: Read, ReadAt, Seek, Close

type FileInfo

type FileInfo struct {
	Path  []byte
	Size  int64
	Mtime int32
	Mode  FileMode
}

type FileList

type FileList []FileInfo

func (FileList) Diff

func (L FileList) Diff(R FileList) (newitems []int, olditems []int)
Diff two sorted rsync file list, return their difference

list NEW: only R has. list OLD: only L has.

func (FileList) Len

func (L FileList) Len() int

func (FileList) Less

func (L FileList) Less(i, j int) bool

func (FileList) Swap

func (L FileList) Swap(i, j int)

type FileMetadata

type FileMetadata struct {
	Mtime int32
	Mode  FileMode
}

type FileMode

type FileMode uint32

For unix/linux

func NewFileMode

func NewFileMode(mode os.FileMode) FileMode

reference: os/types.go

func (FileMode) Convert

func (m FileMode) Convert() os.FileMode

Convert to os.FileMode

func (FileMode) IsBLK

func (m FileMode) IsBLK() bool

func (FileMode) IsDIR

func (m FileMode) IsDIR() bool

func (FileMode) IsFIFO

func (m FileMode) IsFIFO() bool

func (FileMode) IsLNK

func (m FileMode) IsLNK() bool

func (FileMode) IsREG

func (m FileMode) IsREG() bool

func (FileMode) IsSOCK

func (m FileMode) IsSOCK() bool

func (FileMode) Perm

func (m FileMode) Perm() FileMode

Return only unix permission bits

func (FileMode) String

func (m FileMode) String() string

strmode

type MuxReader

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

func NewMuxReader

func NewMuxReader(reader io.ReadCloser) *MuxReader

func (*MuxReader) Close

func (r *MuxReader) Close() error

func (*MuxReader) Read

func (r *MuxReader) Read(p []byte) (n int, err error)

type MuxReaderV0

type MuxReaderV0 struct {
	Data chan byte
	// contains filtered or unexported fields
}

func NewMuxReaderV0

func NewMuxReaderV0(reader io.ReadCloser) *MuxReaderV0

func (*MuxReaderV0) Close

func (r *MuxReaderV0) Close() error

func (*MuxReaderV0) Read

func (r *MuxReaderV0) Read(p []byte) (n int, err error)

FIXME: Never return error

type Receiver

type Receiver struct {
	// contains filtered or unexported fields
}
Receiver:

1. Receive File list 2. Request files by sending files' index 3. Receive Files, pass the files to storage

func (*Receiver) BuildArgs

func (r *Receiver) BuildArgs() string

func (*Receiver) FileCleaner

func (r *Receiver) FileCleaner(localList FileList, deleteList []int) error

Clean up local files

func (*Receiver) FileDownloader

func (r *Receiver) FileDownloader(localList FileList) error

TODO: It is better to update files in goroutine

func (*Receiver) FinalPhase

func (r *Receiver) FinalPhase() error

func (*Receiver) Generator

func (r *Receiver) Generator(remoteList FileList, downloadList []int, symlinks map[string][]byte) error

Generator: handle files: if it's a regular file, send its index. Otherwise, put them to storage

func (*Receiver) RecvFileList

func (r *Receiver) RecvFileList() (FileList, map[string][]byte, error)

Return a filelist from remote

func (*Receiver) SendExclusions

func (r *Receiver) SendExclusions() error

func (*Receiver) StartMuxIn

func (r *Receiver) StartMuxIn()

DeMux was started here

func (*Receiver) Sync

func (r *Receiver) Sync() error

type SSH

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

func NewSSH

func NewSSH(address string, username string, pwd string, cmd string) (*SSH, error)

func (*SSH) Close

func (s *SSH) Close() error

func (*SSH) Read

func (s *SSH) Read(p []byte) (n int, err error)

func (*SSH) Write

func (s *SSH) Write(p []byte) (n int, err error)

type SendReceiver

type SendReceiver interface {
	Sync() error
}

func SocketClient

func SocketClient(storage FS, address string, module string, path string, options map[string][]string, logger *logrus.Logger) (SendReceiver, error)

TODO: passes more arguments: cmd Connect to rsync daemon

func SshClient

func SshClient(storage FS, address string, module string, path string, options map[string]string) (SendReceiver, error)

Connect to sshd, and start a rsync server on remote

type Sender

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

func (*Sender) FileUploader

func (s *Sender) FileUploader() error

func (*Sender) FinalPhase

func (s *Sender) FinalPhase() error

func (*Sender) Generator

func (s *Sender) Generator(fileList FileList) error

func (*Sender) SendFileList

func (s *Sender) SendFileList() error

func (*Sender) Sync

func (s *Sender) Sync() error

type SumChunk

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

type SumStruct

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

Jump to

Keyboard shortcuts

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