[minor] Apply filtering in FinishCommand()

Move filtering logic added in b3dddf1
This commit is contained in:
Aaron Meihm 2016-01-29 12:27:55 -06:00
Родитель 6dee9d490f
Коммит 9f1ec22a7d
1 изменённых файлов: 16 добавлений и 14 удалений

Просмотреть файл

@ -155,20 +155,6 @@ func (db *DB) InsertCommands(cmds []mig.Command) (insertCount int64, err error)
if err != nil {
return int64(i), err
}
// XXX Filter any unicode NULL escape sequences present in the command
// results before we insert. Postgres disallows this value to be present;
// if an entry containing this value is present and JSON processing is done
// on the entry by the database it will result in an error.
//
// See Postgres 9.4.1 release notes for details:
// http://www.postgresql.org/docs/9.4/static/release-9-4-1.html
jRes = bytes.Replace(jRes, []byte("\\u0000"), []byte("NULL"), -1)
// Validate the result is still valid JSON before the insert
var tmpres []modules.Result
err = json.Unmarshal(jRes, &tmpres)
if err != nil {
return int64(i), err
}
if i > 0 {
sql += ", "
}
@ -223,6 +209,22 @@ func (db *DB) FinishCommand(cmd mig.Command) (err error) {
if err != nil {
return fmt.Errorf("Failed to marshal results: '%v'", err)
}
// XXX Filter any unicode NULL escape sequences present in the command
// results before we insert. Postgres disallows this value to be present;
// if an entry containing this value is present and JSON processing is done
// on the entry by the database it will result in an error.
//
// See Postgres 9.4.1 release notes for details:
// http://www.postgresql.org/docs/9.4/static/release-9-4-1.html
jResults = bytes.Replace(jResults, []byte("\\u0000"), []byte("NULL"), -1)
// Validate the result is still valid JSON before the insert
var tmpres []modules.Result
err = json.Unmarshal(jResults, &tmpres)
if err != nil {
return err
}
res, err := db.c.Exec(`UPDATE commands SET status=$1, results=$2, finishtime=$3
WHERE id=$4 AND status!=$5 AND agentid IN (
SELECT id FROM agents