Skip to content

Commit

Permalink
Makefile and version information
Browse files Browse the repository at this point in the history
  • Loading branch information
bertbaron committed Jun 20, 2017
1 parent fe3d14d commit 2ce6cc3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
all: clean linux

VERSION=`git describe --tags --always --dirty)`
BUILD_TIME=`date +%FT%T%z`
LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"

init:
go get ./...

linux: init
GOOS=linux GOARCH=amd64 go build -o btrdedup .
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o btrdedup .

clean:
-rm -f btrdedup
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ const (
minSize int64 = 4 * 1024
)

var (
version = "undefined"
buildTime = "unknown"
)

type context struct {
pathstore storage.PathStorage
stats *storage.Statistics
state storage.DedupInterface
stats *storage.Statistics
state storage.DedupInterface
}

// readDirNames reads the directory named by dirname
Expand Down Expand Up @@ -168,14 +173,14 @@ func submitForDedup(ctx context, files []*storage.FileInformation, noact bool) {
filenames[i] = ctx.pathstore.FilePath(file.Path)
}
if sameOffset {
log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files)-1)
log.Printf("Skipping %s and %d other files, they all have the same physical offset", filenames[0], len(files) - 1)
return
}
if !noact {
log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files)-1)
log.Printf("Offering for deduplication: %s and %d other files\n", filenames[0], len(files) - 1)
Dedup(filenames, 0, uint64(size))
} else {
log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files)-1)
log.Printf("Candidate for deduplication: %s and %d other files\n", filenames[0], len(files) - 1)
}
}

Expand Down Expand Up @@ -255,13 +260,19 @@ func main() {
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE-OR-DIR]...\n", os.Args[0])
flag.PrintDefaults()
}
showVersion := flag.Bool("version", false, "show version information and exits")
noact := flag.Bool("noact", false, "if provided, the tool will only scan and log results, but not actually deduplicate")
lowmem := flag.Bool("lowmem", false, "if provided, the tool will use much less memory by using temporary files and the external sort command")
nopb := flag.Bool("nopb", false, "if provided, the tool will not show the progress bar")
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
memprofile := flag.String("memprofile", "", "write memory profile to this file")
flag.Parse()

if *showVersion {
fmt.Printf("btrdedup version '%s' built at '%s'\n", version, buildTime)
return
}

if *cpuprofile != "" {
f, err := os.Create((*cpuprofile) + ".prof")
if err != nil {
Expand Down

0 comments on commit 2ce6cc3

Please sign in to comment.