예제 #1
0
// call for each key after all persists added
func (ct *cTest) commit(p priority.List, prev int) error {
	if ct.buffer == nil {
		return nil
	}
	// don't set priorities if any of the persists are identical
	var dupes bool
	for i, v := range ct.buffer {
		if i == len(ct.buffer)-1 {
			break
		}
		for _, v2 := range ct.buffer[i+1:] {
			if v.Equals(v2) {
				dupes = true
				break
			}
		}
	}
	if dupes {
		_, err := ct.bm.Add(bytematcher.SignatureSet(ct.buffer), nil)
		ct.buffer = nil
		return err
	}
	_, err := ct.bm.Add(bytematcher.SignatureSet(ct.buffer), p.Subset(ct.unsatisfied[len(ct.unsatisfied)-len(ct.buffer):], prev))
	ct.buffer = nil
	return err
}
예제 #2
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher, t core.MatcherType) error {
	switch t {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %d", t)
	case core.ExtensionMatcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.Globs()
			l, err := m.Add(stringmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case core.MIMEMatcher:
		if !config.NoMIME() {
			var mimes [][]string
			mimes, p.mPuids = p.j.MIMEs()
			l, err := m.Add(stringmatcher.SignatureSet(mimes), nil)
			if err != nil {
				return err
			}
			p.mStart = l - len(p.mPuids)
			return nil
		}
	case core.ContainerMatcher:
		return p.contMatcher(m)
	case core.ByteMatcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.Signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case core.TextMatcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}
예제 #3
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher) error {
	switch t := m.(type) {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %T", t)
	case extensionmatcher.Matcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.extensions()
			l, err := m.Add(extensionmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case containermatcher.Matcher:
		return p.contMatcher(m)
	case *bytematcher.Matcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case *textmatcher.Matcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}