From 2e556b85f71079e9a66c127607851ba90279258b Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Thu, 10 Sep 2026 22:17:02 -0300 Subject: [PATCH 1/2] gmtwhich/gmtget: Report a failed download through the exit status Both -G (gmtwhich) and -D (gmtget) already detect a missing file after gmt_download_file_if_not_found() (the not-found message, and the error lines it logs) but discarded that outcome and always returned GMT_NOERROR. Track it instead and return GMT_FILE_NOT_FOUND when a requested download did not produce the file. Scoped to -G/-D only (a plain "gmt which localfile" is unaffected) and gmtwhich -C keeps exiting 0, since its whole point is reporting Y/N as text. Tiled dataset listings are not covered here. Fixes #9195 Assisted-by: Claude Sonnet 5 --- src/gmtget.c | 18 ++++++++++++------ src/gmtwhich.c | 6 ++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gmtget.c b/src/gmtget.c index c277f322af3..a0c4160d847 100644 --- a/src/gmtget.c +++ b/src/gmtget.c @@ -184,7 +184,9 @@ EXTERN_MSC void gmt_free_list (struct GMT_CTRL *GMT, char **list, uint64_t n); EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { int error = GMT_NOERROR; - char *datasets = NULL, *c = NULL, file[PATH_MAX] = {""}; + unsigned int first = 0; + bool missing = false; + char *datasets = NULL, *c = NULL, file[PATH_MAX] = {""}, path[PATH_MAX] = {""}; struct GMTGET_CTRL *Ctrl = NULL; struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL; @@ -280,13 +282,16 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { else { if (API->remote_info[k].tile_size > 0.0) { /* Must obtain all tiles */ char **list = gmt_get_dataset_tiles (API, world, k, &n_tiles, NULL); - for (t = 0; t < n_tiles; t++) - gmt_download_file_if_not_found (GMT, list[t], GMT_AUTO_DIR); + for (t = 0; t < n_tiles; t++) { + first = gmt_download_file_if_not_found (GMT, list[t], GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &list[t][first], path, R_OK) == NULL) missing = true; + } gmt_free_list (GMT, list, n_tiles); } else { sprintf (file, "@%s", API->remote_info[k].file); - gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + first = gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &file[first], path, R_OK) == NULL) missing = true; } } } @@ -314,11 +319,12 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { fgets (line, GMT_LEN256, fp); /* Skip first record with record count */ while (fscanf (fp, "%s %*s %*s", line) == 1) { sprintf (file, "@%s", line); - gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + first = gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &file[first], path, R_OK) == NULL) missing = true; } fclose (fp); } - Return (GMT_NOERROR); + Return (missing ? GMT_FILE_NOT_FOUND : GMT_NOERROR); } /* Read the supplied default file or the users defaults to override system settings */ diff --git a/src/gmtwhich.c b/src/gmtwhich.c index 20686a1fce2..cc94e572617 100644 --- a/src/gmtwhich.c +++ b/src/gmtwhich.c @@ -197,7 +197,7 @@ GMT_LOCAL int gmtwhich_list_tiles (struct GMTAPI_CTRL *API, char *list, unsigned #define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);} EXTERN_MSC int GMT_gmtwhich (void *V_API, int mode, void *args) { - bool list; + bool list, missing = false; int error = 0, fmode, k_data; unsigned int first = 0; /* Real start of filename */ @@ -294,6 +294,7 @@ EXTERN_MSC int GMT_gmtwhich (void *V_API, int mode, void *args) { GMT_Put_Record (API, GMT_WRITE_DATA, Out); } GMT_Report (API, GMT_MSG_ERROR, "File %s not found!\n", &file[first]); + if (Ctrl->G.active) missing = true; /* Asked to fetch it and still don't have it */ } } @@ -302,5 +303,6 @@ EXTERN_MSC int GMT_gmtwhich (void *V_API, int mode, void *args) { Return (API->error); } - Return (GMT_NOERROR); + /* -C's purpose is to report Y/N as text without erroring, so it always keeps exiting 0 */ + Return ((missing && !Ctrl->C.active) ? GMT_FILE_NOT_FOUND : GMT_NOERROR); } From 475ed8d7549b274e30ee9c909f8b3e52c0d4caf7 Mon Sep 17 00:00:00 2001 From: Esteban82 Date: Thu, 10 Sep 2026 23:01:18 -0300 Subject: [PATCH 2/2] gmtget: Drop tiled-dataset failure detection, use a fixed offset The tiled-dataset branch needs its own JP2-vs-netCDF existence check (a tile that -N leaves as JP2 is still present), which duplicates logic gmt_set_remote_and_local_filenames() already gets right internally. Rather than reimplementing it, leave tiled datasets unchecked here, same as gmt which -G already does. For the two remaining checks, use a fixed offset of 1 instead of the return value of gmt_download_file_if_not_found(): every file name here is built locally as "@%s", so the offset is always 1. Assisted-by: Claude Sonnet 5, reviewed by Claude Opus 5 --- src/gmtget.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/gmtget.c b/src/gmtget.c index a0c4160d847..4a4fb196563 100644 --- a/src/gmtget.c +++ b/src/gmtget.c @@ -184,7 +184,6 @@ EXTERN_MSC void gmt_free_list (struct GMT_CTRL *GMT, char **list, uint64_t n); EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { int error = GMT_NOERROR; - unsigned int first = 0; bool missing = false; char *datasets = NULL, *c = NULL, file[PATH_MAX] = {""}, path[PATH_MAX] = {""}; @@ -282,16 +281,14 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { else { if (API->remote_info[k].tile_size > 0.0) { /* Must obtain all tiles */ char **list = gmt_get_dataset_tiles (API, world, k, &n_tiles, NULL); - for (t = 0; t < n_tiles; t++) { - first = gmt_download_file_if_not_found (GMT, list[t], GMT_AUTO_DIR); - if (gmt_getdatapath (GMT, &list[t][first], path, R_OK) == NULL) missing = true; - } + for (t = 0; t < n_tiles; t++) + gmt_download_file_if_not_found (GMT, list[t], GMT_AUTO_DIR); gmt_free_list (GMT, list, n_tiles); } else { sprintf (file, "@%s", API->remote_info[k].file); - first = gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); - if (gmt_getdatapath (GMT, &file[first], path, R_OK) == NULL) missing = true; + gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &file[1], path, R_OK) == NULL) missing = true; } } } @@ -319,8 +316,8 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { fgets (line, GMT_LEN256, fp); /* Skip first record with record count */ while (fscanf (fp, "%s %*s %*s", line) == 1) { sprintf (file, "@%s", line); - first = gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); - if (gmt_getdatapath (GMT, &file[first], path, R_OK) == NULL) missing = true; + gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &file[1], path, R_OK) == NULL) missing = true; } fclose (fp); }