diff --git a/base/remove.go b/base/remove.go index 2fcf6a4d3..b9b5ea691 100644 --- a/base/remove.go +++ b/base/remove.go @@ -51,7 +51,7 @@ func RemoveEntireDataset(ctx context.Context, r repo.Repo, ref dsref.Ref, histor removeErr = err } } else { - if err := book.RemoveAnyoneLog(ctx, ref); err == nil { + if err := book.RemoveLog(ctx, ref); err == nil { didRemove = appendString(didRemove, "logbook") } else { log.Debugf("Remove, logbook.RemoveLog failed, error: %s", err) diff --git a/fsi/init.go b/fsi/init.go index 7ff9341c3..c982162db 100644 --- a/fsi/init.go +++ b/fsi/init.go @@ -128,7 +128,7 @@ to create a working directory for an existing dataset` rollback = concatFunc( func() { log.Debugf("removing log from logbook %q", ref) - if err := book.RemoveLog(ctx, book.Author(), ref); err != nil { + if err := book.RemoveLog(ctx, ref); err != nil { log.Error(err) } }, rollback) diff --git a/logbook/logbook.go b/logbook/logbook.go index 52164d90a..45f4b3907 100644 --- a/logbook/logbook.go +++ b/logbook/logbook.go @@ -826,43 +826,7 @@ func (book *Book) MergeLog(ctx context.Context, sender identity.Author, lg *oplo } // RemoveLog removes an entire log from a logbook -func (book *Book) RemoveLog(ctx context.Context, sender identity.Author, ref dsref.Ref) error { - if book == nil { - return ErrNoLogbook - } - - l, err := book.BranchRef(ctx, ref) - if err != nil { - return err - } - - // eventually access control will dictate which logs can be written by whom. - // For now we only allow users to merge logs they've written - // book will need access to a store of public keys before we can verify - // signatures non-same-senders - // if err := l.Verify(sender.AuthorPubKey()); err != nil { - // return err - // } - - root := l - for { - p := root.Parent() - if p == nil { - break - } - root = p - } - - if root.ID() != sender.AuthorID() { - return fmt.Errorf("authors can only remove logs they own") - } - - book.store.RemoveLog(ctx, dsRefToLogPath(ref)...) - return book.save(ctx) -} - -// RemoveAnyoneLog removes a log owned by anyone. -func (book *Book) RemoveAnyoneLog(ctx context.Context, ref dsref.Ref) error { +func (book *Book) RemoveLog(ctx context.Context, ref dsref.Ref) error { if book == nil { return ErrNoLogbook } diff --git a/logbook/logbook_test.go b/logbook/logbook_test.go index c4acd7989..ed6df6004 100644 --- a/logbook/logbook_test.go +++ b/logbook/logbook_test.go @@ -198,7 +198,7 @@ func TestNilCallable(t *testing.T) { if err = book.MergeLog(ctx, nil, &oplog.Log{}); err != logbook.ErrNoLogbook { t.Errorf("expected '%s', got: %v", logbook.ErrNoLogbook, err) } - if err = book.RemoveLog(ctx, nil, dsref.Ref{}); err != logbook.ErrNoLogbook { + if err = book.RemoveLog(ctx, dsref.Ref{}); err != logbook.ErrNoLogbook { t.Errorf("expected '%s', got: %v", logbook.ErrNoLogbook, err) } if err = book.ConstructDatasetLog(ctx, dsref.Ref{}, nil); err != logbook.ErrNoLogbook { diff --git a/logbook/logsync/logsync.go b/logbook/logsync/logsync.go index bd683eb25..a2f255937 100644 --- a/logbook/logsync/logsync.go +++ b/logbook/logsync/logsync.go @@ -271,7 +271,33 @@ func (lsync *Logsync) del(ctx context.Context, sender identity.Author, ref dsref } } - if err := lsync.book.RemoveLog(ctx, sender, ref); err != nil { + l, err := lsync.book.BranchRef(ctx, ref) + if err != nil { + return err + } + + // eventually access control will dictate which logs can be written by whom. + // For now we only allow users to merge logs they've written + // book will need access to a store of public keys before we can verify + // signatures non-same-senders + // if err := l.Verify(sender.AuthorPubKey()); err != nil { + // return err + // } + + root := l + for { + p := root.Parent() + if p == nil { + break + } + root = p + } + + if root.ID() != sender.AuthorID() { + return fmt.Errorf("authors can only remove logs they own") + } + + if err := lsync.book.RemoveLog(ctx, ref); err != nil { return err } diff --git a/remote/mock_client.go b/remote/mock_client.go index 364d93f81..137d429b7 100644 --- a/remote/mock_client.go +++ b/remote/mock_client.go @@ -49,7 +49,7 @@ func (c *MockClient) FetchLogs(ctx context.Context, ref dsref.Ref, remoteAddr st return nil, ErrNotImplemented } -// CloneLogs is not implemented +// CloneLogs creates a log from a temp logbook, and merges those into the client's logbook func (c *MockClient) CloneLogs(ctx context.Context, ref dsref.Ref, remoteAddr string) error { tmpdir, err := ioutil.TempDir("", "") if err != nil {