Commit aee78246 authored by 黄大凯's avatar 黄大凯
Browse files

Filelist parser completed

parent 906a6823
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
package main

import (
	"bytes"
	"fmt"
	"io"
	"net"
@@ -79,14 +78,20 @@ func Client() {

	data := make(chan byte, 1024*1024)
	go rsync.DeMuxChan(conn, data)
	parent := new(bytes.Buffer)

	filelist := make([]rsync.FileInfo, 0, 3072)
	// recv_file_list
	for {
		if rsync.GetEntry(data, parent) == io.EOF {
		if rsync.GetEntry(data, &filelist) == io.EOF {
			break
		}
	}
	fmt.Println("Received File List OK, total size is", len(filelist))

	ioerr := rsync.GetInteger(data)
	fmt.Println("IOERR", ioerr)

	// Generate target file list

}

+1 −2
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ func DeMuxBuf(conn net.Conn, buf *bytes.Buffer) {
				return
			}

			buf.Write(body)


		} else {	// out-of-band data
@@ -132,7 +131,7 @@ func DeMuxChan(conn net.Conn, data chan byte) {
		tag := header[3]	// Little Endian
		size := (binary.LittleEndian.Uint32(header) & 0xffffff)		// TODO: zero?

		fmt.Println("TAG", tag, "SIZE", size)
		fmt.Println("*****TAG", tag, "SIZE", size, "*****")

		if tag == 7 {	// MUL_BASE + MSG_DATA
			body := make([]byte, size)
+37 −9
Original line number Diff line number Diff line
package rsync

import (
	"bytes"
	"fmt"
	"io"
)
@@ -13,9 +12,16 @@ func handshake() {
	
}

type FileInfo struct {
	Path string
	Size int64
	Mtime int32
	Mode int32
}


// file list: ends with '\0'
func GetEntry(ds chan byte, parent *bytes.Buffer) error {
func GetEntry(ds chan byte, filelist *[]FileInfo) error {

	flags := <- ds

@@ -53,29 +59,44 @@ func GetEntry(ds chan byte, parent *bytes.Buffer) error {
	// TODO: if pathlen + partical == 0
	// malloc len error?

	/* If so, use last */
	if (0x20 & flags) != 0 {
		// return last 4096bytes
	}
	// last := (*filelist)[len(*filelist) - 1]	// FIXME


	p := make([]byte, pathlen)
	GetBytes(ds, p)
	fmt.Println("Path ", string(p))
	var path string
	/* If so, use last */
	if (0x20 & flags) != 0 {	// FLIST_NAME_SAME
		last := (*filelist)[len(*filelist) - 1]
		path = last.Path[0: partial]
	}
	path += string(p)
	fmt.Println("Path ", path)

	size := GetVarint(ds)
	fmt.Println("Size ", size)

	/* Read the modification time. */
	var mtime int32
	if (flags & 0x80) == 0 {
		fmt.Println("MTIME ", GetInteger(ds))
		mtime = GetInteger(ds)

	} else {
		mtime = (*filelist)[len(*filelist) - 1].Mtime
	}
	fmt.Println("MTIME ", mtime)

	/* Read the file mode. */
	var mode int32
	if (flags & 0x02) == 0 {
		mode = GetInteger(ds)
		fmt.Println("Mode", uint32(mode))

	} else {
		mode = (*filelist)[len(*filelist) - 1].Mode
	}
	fmt.Println("Mode", uint32(mode))

	// FIXME: Sym link
	if ((mode & 32768) != 0) && ((mode & 8192) != 0) {
		len := uint32(GetInteger(ds))
		slink := make([]byte, len)
@@ -83,6 +104,13 @@ func GetEntry(ds chan byte, parent *bytes.Buffer) error {
		fmt.Println("Symbolic Len", len, "CTX", slink)
	}

	*filelist = append(*filelist, FileInfo{
		Path:  path,
		Size:  size,
		Mtime: mtime,
		Mode:  mode,
	})

	return nil
}