예제 #1
0
파일: fetch.go 프로젝트: llitfkitfk/glow
// TODO: this does not work yet. leave it here for later
// temporarily use FetchUrl() for now
// http://localhost:port/content
func Fetch(fileUrl string, destFile string) {

	referenceFileIndex, checksumLookup, fileSize, _ := fetchIndex("somewhere")

	blockCount := fileSize / BLOCK_SIZE
	if fileSize%BLOCK_SIZE != 0 {
		blockCount++
	}

	fs := &gosync.BasicSummary{
		ChecksumIndex:  referenceFileIndex,
		ChecksumLookup: checksumLookup,
		BlockCount:     uint(blockCount),
		BlockSize:      uint(BLOCK_SIZE),
		FileSize:       fileSize,
	}

	rsyncObject, err := gosync.MakeRSync(
		destFile,
		fileUrl,
		destFile,
		fs,
	)

	err = rsyncObject.Patch()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	err = rsyncObject.Close()

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

}
예제 #2
0
파일: patch.go 프로젝트: jbreiding/go-sync
// Patch a file
func Patch(c *cli.Context) {
	errorWrapper(c, func(c *cli.Context) error {

		fmt.Fprintln(os.Stderr, "Starting patching process")

		if l := len(c.Args()); l < 3 || l > 4 {
			return fmt.Errorf(
				"Usage is \"%v\" (invalid number of arguments)",
				usage,
			)
		}

		localFilename := c.Args()[0]
		summaryFile := c.Args()[1]
		referencePath := c.Args()[2]

		outFilename := localFilename
		if len(c.Args()) == 4 {
			outFilename = c.Args()[3]
		}

		indexReader, e := os.Open(summaryFile)
		if e != nil {
			return e
		}
		defer indexReader.Close()

		_, _, _, filesize, blocksize, e := readHeadersAndCheck(
			indexReader,
			magicString,
			majorVersion,
		)

		index, checksumLookup, blockCount, err := readIndex(
			indexReader,
			uint(blocksize),
		)

		fs := &gosync_main.BasicSummary{
			ChecksumIndex:  index,
			ChecksumLookup: checksumLookup,
			BlockCount:     blockCount,
			BlockSize:      uint(blocksize),
			FileSize:       filesize,
		}

		rsync, err := gosync_main.MakeRSync(
			localFilename,
			referencePath,
			outFilename,
			fs,
		)

		if err != nil {
			return err
		}

		err = rsync.Patch()

		if err != nil {
			return err
		}

		return rsync.Close()
	})
}