-SELECT s.id, s.file FROM source s
- WHERE NOT EXISTS
- (SELECT sa.suite FROM src_associations sa WHERE sa.source = s.id)
- AND NOT EXISTS (SELECT b.id FROM binaries b WHERE b.source = s.id)""");
+SELECT s.id, s.file FROM source s, files f
+ WHERE f.last_used IS NULL AND s.file = f.id
+ AND NOT EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id)
+ AND NOT EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)""");