Skip to content

Commit a2c6644

Browse files
committed
Updated 'update-license' binary to handle if the crate doesn't currently have a license.
1 parent 41ae4c0 commit a2c6644

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/bin/update-licenses.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,26 @@ fn transfer(tx: &postgres::transaction::Transaction) {
2727
for row in rows.iter() {
2828
let id: i32 = row.get("id");
2929
let name: String = row.get("name");
30-
let license: String = row.get("license");
31-
32-
println!(
33-
"Setting the license for all versions of {} to {}.",
34-
name,
35-
license
36-
);
37-
38-
let num_updated = tx.execute(
39-
"UPDATE versions SET license = $1 WHERE crate_id = $2",
40-
&[&license, &id],
41-
).unwrap();
42-
assert!(num_updated > 0);
30+
let license: Option<String> = row.get("license");
31+
32+
if let Some(license) = license {
33+
println!(
34+
"Setting the license for all versions of {} to {}.",
35+
name,
36+
license
37+
);
38+
39+
let num_updated = tx.execute(
40+
"UPDATE versions SET license = $1 WHERE crate_id = $2",
41+
&[&license, &id],
42+
).unwrap();
43+
assert!(num_updated > 0);
44+
} else {
45+
println!(
46+
"Ignoring crate `{}` because it doesn't have a license.",
47+
name
48+
);
49+
}
4350
}
4451

4552
get_confirm("Finish committing?");

0 commit comments

Comments
 (0)