Skip to content

update for go1.5+ #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Folders
_obj
_test
vendor

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -18,6 +19,7 @@ _cgo_gotypes.go
_cgo_export.*

_testmain.go
gosync-cmd

*.exe
*.test
Expand Down
33 changes: 33 additions & 0 deletions README.e.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# {{.Name}}

{{template "badge/travis" .}}{{template "badge/appveyor" .}}{{template "badge/godoc" .}}

{{pkgdoc}}

This forks the CLI code that was originally in https://github.com/Redundancy/go-sync
In order to separate the library from the tool, and to bring proper vendoring to the tool.

# Install

### Glide

{{template "glide/install" .}}

### run/build

```sh
go run *.go
go build -o gosync-cmd *.go
emd gen -out README.md
```

# Usage

{{cli "./gosync-cmd" "-h"}}
{{cli "./gosync-cmd" "build" "-h"}}
{{cli "./gosync-cmd" "diff" "-h"}}
{{cli "./gosync-cmd" "patch" "-h"}}

## Cli examples

???
111 changes: 110 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,114 @@
# gosync-cmd
Command-line tool based on gosync

[![travis Status](https://travis-ci.org/mh-cbon/gosync-cmd.svg?branch=master)](https://travis-ci.org/mh-cbon/gosync-cmd)[![appveyor Status](https://ci.appveyor.com/api/projects/status/github/mh-cbon/gosync-cmd?branch=master&svg=true)](https://ci.appveyor.com/project/mh-cbon/gosync-cmd)
[![GoDoc](https://godoc.org/github.com/mh-cbon/gosync-cmd?status.svg)](http://godoc.org/github.com/mh-cbon/gosync-cmd)


Package gosync-cmd is a command-line implementation
of the gosync package functionality,
primarily as a demonstration of usage
but supposed to be functional in itself.


This forks the CLI code that was originally in https://github.com/Redundancy/go-sync
In order to separate the library from the tool, and to bring proper vendoring to the tool.

# Install

### Glide


```sh
mkdir -p $GOPATH/src/github.com/mh-cbon/gosync-cmd
cd $GOPATH/src/github.com/mh-cbon/gosync-cmd
git clone https://github.com/mh-cbon/gosync-cmd.git .
glide install
go install
```


### run/build

```sh
go run *.go
go build -o gosync-cmd *.go
emd gen -out README.md
```

# Usage


__$ gosync-cmd -h__
```sh
NAME:
gosync - Build indexes, patches, patch files

USAGE:
gosync-cmd [global options] command [command options] [arguments...]

VERSION:
0.2.1

COMMANDS:
build, b build a .gosync file for a file
diff, d gosync diff <localfile> <reference.gosync>
patch, p gosync patch <localfile> <reference index> <reference source> [<output>]
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--profile enable HTTP profiling
--profilePort value The number of streams to use concurrently (default: 6060)
--help, -h show help
--version, -v print the version
```

__$ gosync-cmd build -h__
```sh
NAME:
gosync-cmd build - build a .gosync file for a file

USAGE:
gosync-cmd build [command options] [arguments...]

OPTIONS:
--blocksize value The block size to use for the gosync file (default: 8192)
```

__$ gosync-cmd diff -h__
```sh
NAME:
gosync-cmd diff - gosync diff <localfile> <reference.gosync>

USAGE:
gosync-cmd diff [command options] [arguments...]

DESCRIPTION:
Compare a file with a reference index, and print statistics on the comparison and performance.

OPTIONS:
-p value The number of streams to use concurrently (default: 4)
```

__$ gosync-cmd patch -h__
```sh
NAME:
gosync-cmd patch - gosync patch <localfile> <reference index> <reference source> [<output>]

USAGE:
gosync-cmd patch [command options] [arguments...]

DESCRIPTION:
Recreate the reference source file, using an index and a local file that is believed to be similar.
The index should be produced by "gosync build".

<reference index> is a .gosync file and may be a local, unc network path or http/https url
<reference source> is corresponding target and may be a local, unc network path or http/https url
<output> is optional. If not specified, the local file will be overwritten when done.

OPTIONS:
-p value The number of streams to use concurrently (default: 4)
```

## Cli examples

???
12 changes: 7 additions & 5 deletions src/gosync/build.go → build.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package gosync-cmd is a command-line tool based on gosync
package main

import (
Expand Down Expand Up @@ -29,6 +30,7 @@ func init() {
)
}

// Build builds a .gosync file for a file
func Build(c *cli.Context) {
filename := c.Args()[0]
blocksize := uint32(c.Int("blocksize"))
Expand All @@ -48,7 +50,7 @@ func Build(c *cli.Context) {

s, _ := inputFile.Stat()
// TODO: Error?
file_size := s.Size()
fileSize := s.Size()

defer inputFile.Close()

Expand All @@ -67,12 +69,12 @@ func Build(c *cli.Context) {
outputFile,
magicString,
blocksize,
file_size,
fileSize,
[]uint16{majorVersion, minorVersion, patchVersion},
); err != nil {
fmt.Fprintf(
os.Stderr,
"Error getting file info: %v\n",
"Error getting file info: %q %v\n",
filename,
err,
)
Expand All @@ -86,7 +88,7 @@ func Build(c *cli.Context) {
if err != nil {
fmt.Fprintf(
os.Stderr,
"Error generating checksum: %v\n",
"Error generating checksum: %q %v\n",
filename,
err,
)
Expand All @@ -97,7 +99,7 @@ func Build(c *cli.Context) {
if err != nil {
fmt.Fprintf(
os.Stderr,
"Error getting file info: %v\n",
"Error getting file info: %q %v\n",
filename,
err,
)
Expand Down
File renamed without changes.
14 changes: 8 additions & 6 deletions ...hub.com/Redundancy/go-sync/gosync/diff.go → diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func init() {
)
}

// Diff compares a file with a reference index,
// and print statistics on the comparison and performance
func Diff(c *cli.Context) {
localFilename := c.Args()[0]
referenceFilename := c.Args()[1]
Expand Down Expand Up @@ -80,20 +82,20 @@ func Diff(c *cli.Context) {
os.Exit(1)
}

num_matchers := int64(c.Int("p"))
numMatchers := int64(c.Int("p"))

localFile_size := fi.Size()
localFileSize := fi.Size()

// Don't split up small files
if localFile_size < 1024*1024 {
num_matchers = 1
if localFileSize < 1024*1024 {
numMatchers = 1
}

merger, compare := multithreadedMatching(
localFile,
index,
localFile_size,
num_matchers,
localFileSize,
numMatchers,
uint(blocksize),
)

Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package: github.com/mh-cbon/gosync-cmd
import:
- package: github.com/Redundancy/go-sync
subpackages:
- chunks
- comparer
- filechecksum
- index
- patcher
- package: github.com/codegangsta/cli
version: ^1.19.1
9 changes: 5 additions & 4 deletions src/gosync/main.go → main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
gosync is a command-line implementation of the gosync package functionality, primarily as a demonstration of usage
but supposed to be functional in itself.
*/
// Package gosync-cmd is a command-line implementation
// of the gosync package functionality,
// primarily as a demonstration of usage
// but supposed to be functional in itself.
package main

import (
Expand All @@ -16,6 +16,7 @@ import (
)

const (
// DefaultBlockSize is ...
DefaultBlockSize = 8192
magicString = "G0S9NC" // just to confirm the file type is used correctly
majorVersion = uint16(0)
Expand Down
14 changes: 11 additions & 3 deletions ...ub.com/Redundancy/go-sync/gosync/patch.go → patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ The index should be produced by "gosync build".
)
}

// Patch a file
// Patch recreates the reference source file,
// using an index and a local file that is believed to be similar.
// The index should be produced by "gosync build".
//
// <reference index> is a .gosync file and may be a local, unc network path or http/https url
// <reference source> is corresponding target and may be a local, unc network path or http/https url
// <output> is optional. If not specified, the local file will be overwritten when done.
func Patch(c *cli.Context) {
errorWrapper(c, func(c *cli.Context) error {

Expand Down Expand Up @@ -64,13 +70,15 @@ func Patch(c *cli.Context) {
}
defer indexReader.Close()

_, _, _, filesize, blocksize, e := readHeadersAndCheck(
// TODO why this err is ignored ?
_, _, _, filesize, blocksize, _ := readHeadersAndCheck(
indexReader,
magicString,
majorVersion,
)

index, checksumLookup, blockCount, err := readIndex(
// TODO why this err is ignored ?
index, checksumLookup, blockCount, _ := readIndex(
indexReader,
uint(blocksize),
)
Expand Down
Loading