From a743290316332fcdac1caa79721bace55dc9351d Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 28 Apr 2015 16:05:52 -0700 Subject: [PATCH 1/3] blocks: Don't re-Put blocks we already have Commit 1192be196b3d0acca2e2dce5ffd5d12a924fdc5a tried to do this, but had a simple mistake. Functions returning `bool, error` pretty much never return `true, anError`, so that branch was never taken. Also fix the partial sentence in the --- blocks/blockstore/blockstore.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blocks/blockstore/blockstore.go b/blocks/blockstore/blockstore.go index ccc7e8fc5..244d4578a 100644 --- a/blocks/blockstore/blockstore.go +++ b/blocks/blockstore/blockstore.go @@ -64,10 +64,11 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) { } func (bs *blockstore) Put(block *blocks.Block) error { - // Has is cheaper than k := block.Key().DsKey() + + // Has is cheaper than Put, so see if we already have it exists, err := bs.datastore.Has(k) - if err != nil && exists { + if err == nil && exists { return nil // already stored. } return bs.datastore.Put(k, block.Data) From a0af9f5e8d19d1ed469ff1ab025fd1923075cd16 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 28 Apr 2015 16:18:09 -0700 Subject: [PATCH 2/3] If ErrNoRepo is not an error value anymore, then make it an error type --- repo/fsrepo/fsrepo.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 1717dfd91..391e00882 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -40,11 +40,20 @@ Please run the ipfs migration tool before continuing. ` + migrationInstructions var ( - ErrNoRepo = func (path string) error { return fmt.Errorf("no ipfs repo found in '%s'. please run: ipfs init ", path) } ErrNoVersion = errors.New("no version file found, please run 0-to-1 migration tool.\n" + migrationInstructions) ErrOldRepo = errors.New("ipfs repo found in old '~/.go-ipfs' location, please run migration tool.\n" + migrationInstructions) ) +type NoRepoError struct { + Path string +} + +var _ error = NoRepoError{} + +func (err NoRepoError) Error() string { + return fmt.Sprintf("no ipfs repo found in '%s'. please run: ipfs init ", err.Path) +} + const ( leveldbDirectory = "datastore" flatfsDirectory = "blocks" @@ -172,7 +181,7 @@ func checkInitialized(path string) error { if isInitializedUnsynced(alt) { return ErrOldRepo } - return ErrNoRepo(path) + return NoRepoError{Path: path} } return nil } From e78305546c4e72b8a8f568c92c1f86330563aa2d Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Tue, 28 Apr 2015 16:18:26 -0700 Subject: [PATCH 3/3] gofmt --- cmd/ipfs/main.go | 1 - commands/cli/helptext.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 8024471a2..da4946aac 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -116,7 +116,6 @@ func main() { } } - // ok now handle parse error (which means cli input was wrong, // e.g. incorrect number of args, or nonexistent subcommand) if parseErr != nil { diff --git a/commands/cli/helptext.go b/commands/cli/helptext.go index 9d607c0fd..f9ca4d127 100644 --- a/commands/cli/helptext.go +++ b/commands/cli/helptext.go @@ -14,8 +14,8 @@ const ( requiredArg = "<%v>" optionalArg = "[<%v>]" variadicArg = "%v..." - shortFlag = "-%v" - longFlag = "--%v" + shortFlag = "-%v" + longFlag = "--%v" optionType = "(%v)" whitespace = "\r\n\t "