Skip to content

Commit

Permalink
don't diff against existing data if performing a resync
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Nov 10, 2023
1 parent 668f3da commit f5d0616
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions carstore/bs.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ func BlockDiff(ctx context.Context, bs blockstore.Blockstore, oldroot cid.Cid, n
keepset[c] = true
oblk, err := bs.Get(ctx, c)
if err != nil {
return nil, err
return nil, fmt.Errorf("get failed in new tree: %w", err)
}

if err := cbg.ScanForLinks(bytes.NewReader(oblk.RawData()), func(lnk cid.Cid) {
Expand All @@ -901,7 +901,7 @@ func BlockDiff(ctx context.Context, bs blockstore.Blockstore, oldroot cid.Cid, n

oblk, err := bs.Get(ctx, c)
if err != nil {
return nil, err
return nil, fmt.Errorf("get failed in old tree: %w", err)
}

if err := cbg.ScanForLinks(bytes.NewReader(oblk.RawData()), func(lnk cid.Cid) {
Expand Down
9 changes: 9 additions & 0 deletions cmd/gosky/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var syncGetRepoCmd = &cli.Command{
Name: "get-repo",
Usage: "download repo from account's PDS to local file (or '-' for stdout). for hex combine with 'xxd -ps -u -c 0'",
ArgsUsage: `<at-identifier> [<car-file-path>]`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
},
},
Action: func(cctx *cli.Context) error {
ctx := context.Background()
arg := cctx.Args().First()
Expand Down Expand Up @@ -57,6 +62,10 @@ var syncGetRepoCmd = &cli.Command{
return fmt.Errorf("no PDS endpoint for identity")
}

if h := cctx.String("host"); h != "" {
xrpcc.Host = h
}

log.Infof("downloading from %s to: %s", xrpcc.Host, carPath)
repoBytes, err := comatproto.SyncGetRepo(ctx, xrpcc, ident.DID.String(), "")
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions repomgr/repomgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,12 @@ func (rm *RepoManager) ImportNewRepo(ctx context.Context, user models.Uid, repoD
return err
}

if rev == nil {
// if 'rev' is nil, this implies a fresh sync.
// in this case, ignore any existing blocks we have and treat this like a clean import.
curhead = cid.Undef
}

if rev != nil && *rev != currev {
// TODO: we could probably just deal with this
return fmt.Errorf("ImportNewRepo called with incorrect base")
Expand Down

0 comments on commit f5d0616

Please sign in to comment.