(ctx context.Context)
| 125 | } |
| 126 | |
| 127 | func (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 | |
| 153 | func (r *Root) readMagic(ctx context.Context) error { |
| 154 | path := r.path.JoinPath(MagicFile) |
no test coverage detected