|
7 | 7 | #include "trans_priv.h" |
8 | 8 | #include "../../include/apg/graph.h" |
9 | 9 | #include "../../include/apg/db.h" |
| 10 | +#include "../../include/apg/package.h" |
10 | 11 |
|
11 | 12 | static bool |
12 | 13 | in_strarray(const char **arr, size_t count, const char *name) |
@@ -311,7 +312,72 @@ trans_prepare(struct apg_trans *trans) |
311 | 312 | } |
312 | 313 | } |
313 | 314 |
|
314 | | - if (trans->blocked_remove_count > 0) |
| 315 | + for (size_t i = 0; i < trans->install_count; i++) |
| 316 | + { |
| 317 | + struct package *pkg = trans->install_pkgs[i]; |
| 318 | + if (!pkg->meta || !pkg->meta->name) |
| 319 | + continue; |
| 320 | + |
| 321 | + if (pkg->package_files.count == 0) |
| 322 | + package_collect_files(pkg, "/"); |
| 323 | + |
| 324 | + for (int j = 0; j < pkg->package_files.count; j++) |
| 325 | + { |
| 326 | + const char *path = pkg->package_files.items[j]; |
| 327 | + if (!path) |
| 328 | + continue; |
| 329 | + char *owner = db_owner(trans->db, path); |
| 330 | + if (!owner) |
| 331 | + continue; |
| 332 | + if (strcmp(owner, pkg->meta->name) == 0) |
| 333 | + { |
| 334 | + free(owner); |
| 335 | + continue; |
| 336 | + } |
| 337 | + |
| 338 | + if (!trans->file_conflicts) |
| 339 | + { |
| 340 | + trans->file_conflicts = |
| 341 | + malloc(4 * sizeof(*trans->file_conflicts)); |
| 342 | + if (!trans->file_conflicts) |
| 343 | + { |
| 344 | + free(owner); |
| 345 | + ret = TRANS_ERR_NOMEM; |
| 346 | + goto cleanup; |
| 347 | + } |
| 348 | + trans->file_conflict_cap = 4; |
| 349 | + } |
| 350 | + else if (trans->file_conflict_count == trans->file_conflict_cap) |
| 351 | + { |
| 352 | + size_t new_cap = trans->file_conflict_cap * 2; |
| 353 | + struct trans_file_conflict *tmp = |
| 354 | + realloc(trans->file_conflicts, new_cap * sizeof(*tmp)); |
| 355 | + if (!tmp) |
| 356 | + { |
| 357 | + free(owner); |
| 358 | + ret = TRANS_ERR_NOMEM; |
| 359 | + goto cleanup; |
| 360 | + } |
| 361 | + trans->file_conflicts = tmp; |
| 362 | + trans->file_conflict_cap = new_cap; |
| 363 | + } |
| 364 | + |
| 365 | + struct trans_file_conflict *fc = |
| 366 | + &trans->file_conflicts[trans->file_conflict_count++]; |
| 367 | + fc->path = strdup(path); |
| 368 | + fc->requested_by = strdup(pkg->meta->name); |
| 369 | + fc->owned_by = owner; |
| 370 | + if (!fc->path || !fc->requested_by) |
| 371 | + { |
| 372 | + ret = TRANS_ERR_NOMEM; |
| 373 | + goto cleanup; |
| 374 | + } |
| 375 | + } |
| 376 | + } |
| 377 | + |
| 378 | + if (trans->file_conflict_count > 0) |
| 379 | + ret = TRANS_ERR_FILE_CONFLICT; |
| 380 | + else if (trans->blocked_remove_count > 0) |
315 | 381 | ret = TRANS_ERR_HAS_DEPENDENTS; |
316 | 382 | else if (trans->conflict_count > 0) |
317 | 383 | ret = TRANS_ERR_CONFLICT; |
|
0 commit comments