aboutsummaryrefslogtreecommitdiff
path: root/object/store/packed/writer.go
blob: 59309c245625922211aea52d9b80b10aa2dd12a6 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package packed

import (
	"fmt"
	"io"

	"lindenii.org/go/furgit/object/store"
	"lindenii.org/go/furgit/object/store/packed/internal/ingest"
)

var _ store.PackWriter = (*Packed)(nil)

// WritePack ingests one pack stream into the pack store,
// publishing a pack, index, and reverse index
// under content-addressed names derived from the pack trailer hash.
//
// WritePack consumes the pack stream through its trailer and stops there.
// It does not require src to reach EOF afterward,
// so it is safe on a still-open transport connection,
// such as receive-pack,
// whose peer keeps the connection open to read the response.
//
// The pack must be the last thing the peer sends before that response:
// any bytes arriving immediately after the trailer
// are rejected as a malformed pack.
func (packed *Packed) WritePack(src io.Reader, opts store.PackWriteOptions) error {
	_, err := ingest.WritePack(packed.root, packed.objectFormat, src, opts)
	if err != nil {
		return err //nolint:wrapcheck
	}

	err = packed.Refresh()
	if err != nil {
		return fmt.Errorf("object/store/packed: refresh after pack write: %w", err)
	}

	return nil
}