Skip to content

Commit d2dee7b

Browse files
committed
diag(install): report the OS error from a failed staging copy
The copy loop's failure was reported as 'os 0' because the cleanup and close calls after the loop clobber the thread's last error. Captures it at the failure point, and separates a failed read from a failed write -- copying a payload that another process still holds is a different problem from a full disk. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 536d228 commit d2dee7b

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

‎src/cli/activation_transaction.c‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,17 +1510,33 @@ cbm_activation_transaction_status_t cbm_activation_transaction_stage_file(
15101510
unsigned char buffer[64U * 1024U];
15111511
size_t total = 0;
15121512
bool copied = true;
1513+
/* Captured AT the failure, not after: the cleanup and close calls below all
1514+
* clobber the thread's last error, which is why this path could only ever
1515+
* report "os 0". */
1516+
unsigned long copy_os_error = 0UL;
1517+
bool copy_failed_on_read = false;
15131518
for (;;) {
15141519
size_t amount = 0;
15151520
if (!activation_native_read(source, buffer, sizeof(buffer), &amount)) {
15161521
copied = false;
1522+
copy_failed_on_read = true;
1523+
#ifdef _WIN32
1524+
copy_os_error = (unsigned long)GetLastError();
1525+
#else
1526+
copy_os_error = (unsigned long)errno;
1527+
#endif
15171528
break;
15181529
}
15191530
if (amount == 0) {
15201531
break;
15211532
}
15221533
if (SIZE_MAX - total < amount || !activation_native_write_all(staged, buffer, amount)) {
15231534
copied = false;
1535+
#ifdef _WIN32
1536+
copy_os_error = (unsigned long)GetLastError();
1537+
#else
1538+
copy_os_error = (unsigned long)errno;
1539+
#endif
15241540
break;
15251541
}
15261542
total += amount;
@@ -1536,13 +1552,19 @@ cbm_activation_transaction_status_t cbm_activation_transaction_stage_file(
15361552
* sync are not the same bug. Naming them is what turns a ten-minute
15371553
* guard run per hypothesis into one run that answers the question. */
15381554
activation_failed_stage_cleanup(transaction);
1539-
activation_note_refusal(!copied ? "stage-copy-read-or-write"
1540-
: total == 0 ? "stage-source-empty"
1541-
: !durable ? "stage-fsync"
1542-
: !source_closed ? "stage-source-close"
1543-
: !staged_closed ? "stage-staged-close"
1544-
: "stage-directory-sync",
1545-
0UL);
1555+
const char *why = "stage-directory-sync";
1556+
if (!copied) {
1557+
why = copy_failed_on_read ? "stage-copy-read" : "stage-copy-write";
1558+
} else if (total == 0) {
1559+
why = "stage-source-empty";
1560+
} else if (!durable) {
1561+
why = "stage-fsync";
1562+
} else if (!source_closed) {
1563+
why = "stage-source-close";
1564+
} else if (!staged_closed) {
1565+
why = "stage-staged-close";
1566+
}
1567+
activation_note_refusal(why, copy_os_error);
15461568
return CBM_ACTIVATION_TRANSACTION_IO;
15471569
}
15481570
*transaction_out = transaction;

0 commit comments

Comments
 (0)