1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
use crate::db::*;
use crate::error::Result;
// ------------------------------------------------------- invariant helpers --
/// Repo entries whose candidate was never approved.
///
/// Test-tier only, and deliberately so: this is an invariant the schema does
/// not enforce and production does not check, so the only thing that keeps it
/// true is that a test asserts it on every run. It is gated rather than moved
/// to `tests/common` because reading it needs this module's private helpers,
/// and widening those to let a test out would be the wrong trade.
#[cfg(feature = "test-support")]
pub fn unapproved_index_entries(db: &Db) -> Result<Vec<String>> {
db.read(|c| {
let mut stmt = c.prepare(
"SELECT p.name FROM package p
JOIN release r ON r.id = p.release_id
WHERE p.state='in_index' AND (r.approval_id IS NULL OR NOT EXISTS
(SELECT 1 FROM approval a WHERE a.id = r.approval_id AND a.decision='approved'))",
)?;
let rows = stmt.query_map([], |r| r.get::<_, String>(0))?;
let mut out = Vec::new();
for r in rows {
out.push(r?);
}
Ok(out)
})
}
#[derive(Debug, Clone)]
// Unbuilt stays `pub`: the attention row `approved_but_unbuilt` returns to the web UI and to tests/crash.rs.
pub struct Unbuilt {
pub pkgbase: String,
pub approved: String,
pub serving: String,
pub error: String,
pub build_id: String,
}
pub fn approved_but_unbuilt(db: &Db) -> Result<Vec<Unbuilt>> {
db.read(|c| {
let mut stmt = c.prepare(
"SELECT p.name,
cnd.epoch, cnd.pkgver, cnd.pkgrel,
ser.epoch, ser.pkgver, ser.pkgrel,
COALESCE(b.error, ''), b.id
FROM build b
JOIN pkgbase p ON p.id = b.pkgbase_id
LEFT JOIN candidate cnd ON cnd.id = b.candidate_id
LEFT JOIN release ser ON ser.id = p.current_accepted_release_id
AND ser.state='published'
WHERE b.state = 'failed'
AND b.candidate_id IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM release r WHERE r.candidate_id = b.candidate_id)
AND b.id = (SELECT b2.id FROM build b2
WHERE b2.candidate_id = b.candidate_id
ORDER BY b2.rowid DESC LIMIT 1)
ORDER BY p.name",
)?;
let rows = stmt.query_map([], |r| {
Ok((
r.get::<_, Option<String>>(0)?,
r.get::<_, Option<String>>(1)?,
r.get::<_, Option<String>>(2)?,
r.get::<_, Option<String>>(3)?,
r.get::<_, Option<String>>(4)?,
r.get::<_, Option<String>>(5)?,
r.get::<_, Option<String>>(6)?,
r.get::<_, String>(7)?,
r.get::<_, String>(8)?,
))
})?;
let mut out = Vec::new();
for r in rows {
let (pkgbase, ae, av, ar, se, sv, sr, error, build_id) = r?;
let (pkgbase, av, ar) = match (pkgbase, av, ar) {
(Some(p), Some(v), Some(rel)) => (p, v, rel),
_ => {
return Err(crate::error::Error::Db(
"failed build row without a candidate version".into(),
))
}
};
out.push(Unbuilt {
pkgbase,
approved: crate::pkgver::full_version(&ae.unwrap_or_default(), &av, &ar),
serving: match (sv, sr) {
(Some(v), Some(rel)) => {
crate::pkgver::full_version(&se.unwrap_or_default(), &v, &rel)
}
_ => String::new(),
},
error,
build_id,
});
}
Ok(out)
})
}
|