| 1486 | } activation_unlink_status_t; |
| 1487 | |
| 1488 | static activation_unlink_status_t activation_unlink_expected( |
| 1489 | const cbm_activation_transaction_t *transaction, const char *path, const char *name, |
| 1490 | const activation_file_identity_t *expected, bool allow_windows_deferred) { |
| 1491 | bool exists = false; |
| 1492 | if (!activation_path_matches(transaction, path, name, expected, &exists)) { |
| 1493 | return ACTIVATION_UNLINK_ERROR; |
| 1494 | } |
| 1495 | if (!exists) { |
| 1496 | return ACTIVATION_UNLINK_OK; |
| 1497 | } |
| 1498 | #ifdef _WIN32 |
| 1499 | wchar_t *wide = activation_utf8_to_wide(path); |
| 1500 | if (!wide) { |
| 1501 | return ACTIVATION_UNLINK_ERROR; |
| 1502 | } |
| 1503 | if (DeleteFileW(wide)) { |
| 1504 | free(wide); |
| 1505 | return ACTIVATION_UNLINK_OK; |
| 1506 | } |
| 1507 | DWORD error = GetLastError(); |
| 1508 | bool deferred = allow_windows_deferred && |
| 1509 | (error == ERROR_ACCESS_DENIED || error == ERROR_SHARING_VIOLATION || |
| 1510 | error == ERROR_LOCK_VIOLATION) && |
| 1511 | MoveFileExW(wide, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) != 0; |
| 1512 | free(wide); |
| 1513 | return deferred ? ACTIVATION_UNLINK_DEFERRED : ACTIVATION_UNLINK_ERROR; |
| 1514 | #else |
| 1515 | (void)allow_windows_deferred; |
| 1516 | int result; |
| 1517 | do { |
| 1518 | result = unlinkat(transaction->directory_fd, name, 0); |
| 1519 | } while (result != 0 && errno == EINTR); |
| 1520 | return result == 0 || errno == ENOENT ? ACTIVATION_UNLINK_OK : ACTIVATION_UNLINK_ERROR; |
| 1521 | #endif |
| 1522 | } |
| 1523 | |
| 1524 | static void activation_transaction_destroy(cbm_activation_transaction_t *transaction) { |
| 1525 | if (!transaction) { |
no test coverage detected