Skip to content

Commit eb2c67a

Browse files
authored
Merge pull request DeusData#1628 from DeusData/fix/windows-publish-diagnostics
fix(windows): report why an atomic publish failed instead of blaming the repo
2 parents c82e69e + 10b935c commit eb2c67a

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

‎src/foundation/compat_fs.c‎

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,9 +1039,54 @@ int cbm_rename_replace(const char *src, const char *dst) {
10391039
wchar_t *wdst = cbm_path_to_wide(dst);
10401040
int ret = CBM_NOT_FOUND;
10411041
if (wsrc && wdst) {
1042-
ret = MoveFileExW(wsrc, wdst, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)
1043-
? 0
1044-
: CBM_NOT_FOUND;
1042+
if (MoveFileExW(wsrc, wdst, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
1043+
ret = 0;
1044+
} else {
1045+
/* Translate the Win32 error into errno so callers can report WHY.
1046+
*
1047+
* Callers log `errno` after a failed rename (see
1048+
* finalize.rename_failed in the pipeline). Without this the value
1049+
* is whatever happened to be left there by an unrelated CRT call,
1050+
* so on Windows the one field that should explain an atomic-publish
1051+
* failure was noise. #1620 is exactly that: an ACL problem surfaced
1052+
* to the user as "Pipeline failed. Check repo_path exists and
1053+
* contains source files" — blaming their repository — because
1054+
* ERROR_ACCESS_DENIED never reached the log.
1055+
*
1056+
* ERROR_ACCESS_DENIED is the interesting one here: MoveFileEx needs
1057+
* DELETE on the destination, which a cache file created under an
1058+
* empty or foreign DACL does not grant. */
1059+
DWORD error = GetLastError();
1060+
switch (error) {
1061+
case ERROR_ACCESS_DENIED:
1062+
case ERROR_WRITE_PROTECT:
1063+
errno = EACCES;
1064+
break;
1065+
case ERROR_FILE_NOT_FOUND:
1066+
case ERROR_PATH_NOT_FOUND:
1067+
errno = ENOENT;
1068+
break;
1069+
case ERROR_SHARING_VIOLATION:
1070+
case ERROR_LOCK_VIOLATION:
1071+
case ERROR_USER_MAPPED_FILE:
1072+
errno = EBUSY;
1073+
break;
1074+
case ERROR_NOT_SAME_DEVICE:
1075+
errno = EXDEV;
1076+
break;
1077+
case ERROR_DISK_FULL:
1078+
errno = ENOSPC;
1079+
break;
1080+
case ERROR_INVALID_NAME:
1081+
case ERROR_FILENAME_EXCED_RANGE:
1082+
errno = ENAMETOOLONG;
1083+
break;
1084+
default:
1085+
errno = EIO;
1086+
break;
1087+
}
1088+
ret = CBM_NOT_FOUND;
1089+
}
10451090
}
10461091
free(wsrc);
10471092
free(wdst);

‎src/pipeline/pipeline.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,15 @@ int cbm_pipeline_finalize_staged_generation(char *stage_path, const char *final_
18061806
struct timespec t_fin;
18071807
cbm_clock_gettime(CLOCK_MONOTONIC, &t_fin);
18081808
if (cbm_remove_db_sidecars(stage_path) != 0) {
1809+
/* This returned PERSIST_FAILED with no log at all, which is how #1620
1810+
* presented: every pass succeeded, the worker exited 0, no error-level
1811+
* line was emitted anywhere, and the user was told "Pipeline failed.
1812+
* Check repo_path exists and contains source files" — pointed at their
1813+
* repository for a filesystem permission problem. A publish that fails
1814+
* must say so. */
1815+
char errno_text[16];
1816+
(void)snprintf(errno_text, sizeof(errno_text), "%d", errno);
1817+
cbm_log_error("finalize.sidecar_removal_failed", "errno", errno_text, "stage", stage_path);
18091818
discard_generation_stage(stage_path);
18101819
return CBM_PIPELINE_PERSIST_FAILED;
18111820
}

0 commit comments

Comments
 (0)