From c708aec4a481dbe93bbc2ca5a12db76fa648e89e Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Wed, 25 Oct 2017 18:16:33 -0400 Subject: [PATCH] fact: fix reverse detection --- plugins/fact/factoid.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go index 57d563c..be364cf 100644 --- a/plugins/fact/factoid.go +++ b/plugins/fact/factoid.go @@ -67,15 +67,17 @@ func findAlias(db *sqlx.DB, fact string) (bool, *factoid) { } func (a *alias) save(db *sqlx.DB) error { - ok, _ := findAlias(db, a.Fact) - if ok { + q := `select * from factoid_alias where fact=?` + var offender alias + err := db.Get(&offender, q, a.Next) + if err == nil { return fmt.Errorf("DANGER: an opposite alias already exists") } - _, err := a.resolve(db) + _, err = a.resolve(db) if err != nil { return fmt.Errorf("there is no fact at that destination") } - q := `insert or replace into factoid_alias (fact, next) values (?, ?)` + q = `insert or replace into factoid_alias (fact, next) values (?, ?)` _, err = db.Exec(q, a.Fact, a.Next) if err != nil { return err