MCPcopy Create free account
hub / github.com/brimdata/super / writeMagic

Method writeMagic

db/root.go:127–151  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

125}
126
127func (r *Root) writeMagic(ctx context.Context) error {
128 if err := r.readMagic(ctx); err == nil {
129 return errors.New("database already exists")
130 }
131 magic := &Magic{
132 Magic: MagicString,
133 Version: Version,
134 }
135 serializer := bsupbytes.NewSerializer()
136 serializer.Decorate(sup.StylePackage)
137 if err := serializer.Write(magic); err != nil {
138 return err
139 }
140 if err := serializer.Close(); err != nil {
141 return err
142 }
143 path := r.path.JoinPath(MagicFile)
144 err := r.engine.PutIfNotExists(ctx, path, serializer.Bytes())
145 if err == storage.ErrNotSupported {
146 //XXX workaround for now: see issue #2686
147 reader := bytes.NewReader(serializer.Bytes())
148 err = storage.Put(ctx, r.engine, path, reader)
149 }
150 return err
151}
152
153func (r *Root) readMagic(ctx context.Context) error {
154 path := r.path.JoinPath(MagicFile)

Callers 1

createConfigMethod · 0.95

Calls 11

readMagicMethod · 0.95
DecorateMethod · 0.95
WriteMethod · 0.95
CloseMethod · 0.95
BytesMethod · 0.95
NewSerializerFunction · 0.92
PutFunction · 0.92
NewMethod · 0.80
JoinPathMethod · 0.80
PutIfNotExistsMethod · 0.65
NewReaderMethod · 0.45

Tested by

no test coverage detected