diff --git a/src/gmtget.c b/src/gmtget.c index c277f322af3..4a4fb196563 100644 --- a/src/gmtget.c +++ b/src/gmtget.c @@ -184,7 +184,8 @@ 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] = {""}; + 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; @@ -287,6 +288,7 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { else { sprintf (file, "@%s", API->remote_info[k].file); gmt_download_file_if_not_found (GMT, file, GMT_AUTO_DIR); + if (gmt_getdatapath (GMT, &file[1], path, R_OK) == NULL) missing = true; } } } @@ -315,10 +317,11 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { while (fscanf (fp, "%s %*s %*s", line) == 1) { sprintf (file, "@%s", line); 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); } - 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); }