Skip to content
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

blocks: Don't re-Put blocks we already have #1161

Merged
merged 3 commits into from
Apr 28, 2015
Merged
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
5 changes: 3 additions & 2 deletions blocks/blockstore/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions commands/cli/helptext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
13 changes: 11 additions & 2 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -172,7 +181,7 @@ func checkInitialized(path string) error {
if isInitializedUnsynced(alt) {
return ErrOldRepo
}
return ErrNoRepo(path)
return NoRepoError{Path: path}
}
return nil
}
Expand Down