From 3ba67c27db0cf52b120e4f15c09047aa96d3bcb4 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Mon, 30 Mar 2026 18:18:06 +0000 Subject: object/store: Unify writers and fix naming --- object/store/base_quarantine.go | 17 +++++++++++++++++ object/store/dual/dual.go | 7 +++---- object/store/dual/dual_test.go | 6 +++--- object/store/dual/quarantine.go | 2 +- object/store/dual/quarantine_begin.go | 2 +- object/store/quarantine.go | 25 ++++++++++++++----------- object/store/quarantine_writer.go | 21 --------------------- object/store/writer.go | 8 ++++++++ object/store/writer_object.go | 2 +- object/store/writer_pack.go | 2 +- 10 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 object/store/base_quarantine.go delete mode 100644 object/store/quarantine_writer.go create mode 100644 object/store/writer.go diff --git a/object/store/base_quarantine.go b/object/store/base_quarantine.go new file mode 100644 index 00000000..754fb3ee --- /dev/null +++ b/object/store/base_quarantine.go @@ -0,0 +1,17 @@ +package objectstore + +// BaseQuarantine is one quarantined write. It is intended to be embedded. +type BaseQuarantine interface { + // Reader exposes the objects written into this quarantine. + Reader + + // Promote publishes quarantined writes into their final destination. + // + // Promote invalidates the receiver. + Promote() error + + // Discard abandons quarantined writes. + // + // Discard invalidates the receiver. + Discard() error +} diff --git a/object/store/dual/dual.go b/object/store/dual/dual.go index 81dc57d7..3072ae77 100644 --- a/object/store/dual/dual.go +++ b/object/store/dual/dual.go @@ -27,8 +27,7 @@ type Dual struct { } var ( - _ objectstore.Reader = (*Dual)(nil) - _ objectstore.ObjectWriter = (*Dual)(nil) - _ objectstore.PackWriter = (*Dual)(nil) - _ objectstore.WriterQuarantiner = (*Dual)(nil) + _ objectstore.Reader = (*Dual)(nil) + _ objectstore.Writer = (*Dual)(nil) + _ objectstore.Quarantiner = (*Dual)(nil) ) diff --git a/object/store/dual/dual_test.go b/object/store/dual/dual_test.go index d9401c30..9e102734 100644 --- a/object/store/dual/dual_test.go +++ b/object/store/dual/dual_test.go @@ -117,9 +117,9 @@ func TestDualReadsWritesAndQuarantine(t *testing.T) { repo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := newDualStore(t, repo, algo) - quarantiner, ok := any(store).(objectstore.WriterQuarantiner) + quarantiner, ok := any(store).(objectstore.Quarantiner) if !ok { - t.Fatal("dual does not implement WriterQuarantiner") + t.Fatal("dual does not implement Quarantiner") } quarantine, err := quarantiner.BeginQuarantine(objectstore.QuarantineOptions{}) @@ -219,7 +219,7 @@ func TestDualQuarantineDiscardDropsBothHalves(t *testing.T) { repo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: algo, Bare: true}) store := newDualStore(t, repo, algo) - quarantiner := any(store).(objectstore.WriterQuarantiner) + quarantiner := any(store).(objectstore.Quarantiner) quarantine, err := quarantiner.BeginQuarantine(objectstore.QuarantineOptions{}) if err != nil { t.Fatalf("BeginQuarantine: %v", err) diff --git a/object/store/dual/quarantine.go b/object/store/dual/quarantine.go index 6fabd590..fb1048af 100644 --- a/object/store/dual/quarantine.go +++ b/object/store/dual/quarantine.go @@ -19,7 +19,7 @@ type quarantine struct { var ( _ objectstore.ObjectQuarantine = (*quarantine)(nil) _ objectstore.PackQuarantine = (*quarantine)(nil) - _ objectstore.WriterQuarantine = (*quarantine)(nil) + _ objectstore.Quarantine = (*quarantine)(nil) ) func newQuarantine( diff --git a/object/store/dual/quarantine_begin.go b/object/store/dual/quarantine_begin.go index 143bd57d..5c6bc934 100644 --- a/object/store/dual/quarantine_begin.go +++ b/object/store/dual/quarantine_begin.go @@ -5,7 +5,7 @@ import objectstore "codeberg.org/lindenii/furgit/object/store" // BeginQuarantine creates one coordinated dual quarantine spanning both stores. // // Labels: Deps-Borrowed, Life-Parent, Close-No. -func (dual *Dual) BeginQuarantine(opts objectstore.QuarantineOptions) (objectstore.WriterQuarantine, error) { +func (dual *Dual) BeginQuarantine(opts objectstore.QuarantineOptions) (objectstore.Quarantine, error) { objectQ, err := dual.object.BeginObjectQuarantine(opts.Object) if err != nil { return nil, err diff --git a/object/store/quarantine.go b/object/store/quarantine.go index a9ba4f55..6db12084 100644 --- a/object/store/quarantine.go +++ b/object/store/quarantine.go @@ -1,17 +1,20 @@ package objectstore -// Quarantine is one quarantined write. It is intended to be embedded. +// WriterQuarantine represents one quarantined write that accepts both object- +// wise and pack-wise writes. type Quarantine interface { - // Reader exposes the objects written into this quarantine. - Reader + BaseQuarantine + Writer +} - // Promote publishes quarantined writes into their final destination. - // - // Promote invalidates the receiver. - Promote() error +// QuarantineOptions controls the options for one coordinated quarantine creation. +type QuarantineOptions struct { + Object ObjectQuarantineOptions + Pack PackQuarantineOptions +} - // Discard abandons quarantined writes. - // - // Discard invalidates the receiver. - Discard() error +// WriterQuarantiner creates coordinated quarantines that support both object- +// wise and pack-wise writes. +type Quarantiner interface { + BeginQuarantine(opts QuarantineOptions) (Quarantine, error) } diff --git a/object/store/quarantine_writer.go b/object/store/quarantine_writer.go deleted file mode 100644 index f5656a8c..00000000 --- a/object/store/quarantine_writer.go +++ /dev/null @@ -1,21 +0,0 @@ -package objectstore - -// WriterQuarantine represents one quarantined write that accepts both object- -// wise and pack-wise writes. -type WriterQuarantine interface { - Quarantine - ObjectWriter - PackWriter -} - -// QuarantineOptions controls the options for one coordinated quarantine creation. -type QuarantineOptions struct { - Object ObjectQuarantineOptions - Pack PackQuarantineOptions -} - -// WriterQuarantiner creates coordinated quarantines that support both object- -// wise and pack-wise writes. -type WriterQuarantiner interface { - BeginQuarantine(opts QuarantineOptions) (WriterQuarantine, error) -} diff --git a/object/store/writer.go b/object/store/writer.go new file mode 100644 index 00000000..9fa05aba --- /dev/null +++ b/object/store/writer.go @@ -0,0 +1,8 @@ +package objectstore + +// Writer represents a store that could perform both pack ingestions +// and individual object writes. +type Writer interface { + PackWriter + ObjectWriter +} diff --git a/object/store/writer_object.go b/object/store/writer_object.go index 77ffbbcd..a18a5d84 100644 --- a/object/store/writer_object.go +++ b/object/store/writer_object.go @@ -24,7 +24,7 @@ type ObjectWriter interface { // ObjectQuarantine represents one quarantined object-wise write. type ObjectQuarantine interface { - Quarantine + BaseQuarantine ObjectWriter } diff --git a/object/store/writer_pack.go b/object/store/writer_pack.go index 85ce676e..0f78c429 100644 --- a/object/store/writer_pack.go +++ b/object/store/writer_pack.go @@ -45,7 +45,7 @@ type PackWriter interface { // PackQuarantine represents one quarantined pack-wise write. type PackQuarantine interface { - Quarantine + BaseQuarantine PackWriter } -- cgit v1.3.1-10-gc9f91