Write will serialize and store the version as a git blob and return its hash
(repo repository.Repo)
| 220 | // Write will serialize and store the version as a git blob and return |
| 221 | // its hash |
| 222 | func (v *version) Write(repo repository.Repo) (repository.Hash, error) { |
| 223 | // make sure we don't write invalid data |
| 224 | err := v.Validate() |
| 225 | if err != nil { |
| 226 | return "", errors.Wrap(err, "validation error") |
| 227 | } |
| 228 | |
| 229 | data, err := json.Marshal(v) |
| 230 | if err != nil { |
| 231 | return "", err |
| 232 | } |
| 233 | |
| 234 | hash, err := repo.StoreData(data) |
| 235 | if err != nil { |
| 236 | return "", err |
| 237 | } |
| 238 | |
| 239 | // make sure we set the Id when writing in the repo |
| 240 | v.id = entity.DeriveId(data) |
| 241 | |
| 242 | return hash, nil |
| 243 | } |
| 244 | |
| 245 | func makeNonce(len int) []byte { |
| 246 | result := make([]byte, len) |