Beispiel #1
0
// DeleteRevision implements a method of kcd.Deleter.
func (db *DB) DeleteRevision(_ context.Context, revision, corpus string) error {
	rev := kcd.Revision{Revision: revision, Corpus: corpus}
	if err := rev.IsValid(); err != nil {
		return err
	}

	found := false
	for i := len(db.Rev) - 1; i >= 0; i-- {
		if revisionsEqual(db.Rev[i], rev) {
			found = true
			db.Rev = append(db.Rev[:i], db.Rev[i+1:]...)
		}
	}
	if found {
		return nil
	}
	return os.ErrNotExist
}
Beispiel #2
0
// WriteRevision implements a method of kcd.Writer.  This implementation stores
// revisions only in memory, they are not persisted in the indexpack.
func (db *DB) WriteRevision(_ context.Context, rev kcd.Revision, replace bool) error {
	if rev.Revision == "" {
		return errors.New("missing revision marker")
	} else if rev.Corpus == "" {
		return errors.New("missing corpus label")
	}
	if rev.Timestamp.IsZero() {
		rev.Timestamp = time.Now()
	}
	rev.Timestamp = rev.Timestamp.In(time.UTC)
	if replace {
		for i, old := range db.Revs {
			if old.Corpus == rev.Corpus && old.Revision == rev.Revision {
				db.Revs[i].Timestamp = rev.Timestamp
				return nil
			}
		}
	}
	db.Revs = append(db.Revs, rev)
	return nil
}