Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/gmt_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ int gmtlib_file_is_jpeg2000_tile (struct GMTAPI_CTRL *API, char *file) {
}

int gmt_download_file (struct GMT_CTRL *GMT, const char *name, char *url, char *localfile, bool be_fussy) {
bool query = gmt_M_file_is_query (url);
int curl_err, error;
size_t fsize;
char *Lfile = NULL;
Expand All @@ -1135,12 +1136,14 @@ int gmt_download_file (struct GMT_CTRL *GMT, const char *name, char *url, char *

/* Here we will try to download a file */

Lfile = gmtremote_lockfile (API, (char *)name);
if ((fp = fopen (Lfile, "w")) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "Failed to create lock file %s\n", Lfile);
return 1;
if (!query) { /* Only make a filename if not a query */
Lfile = gmtremote_lockfile (API, (char *)name);
if ((fp = fopen (Lfile, "w")) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "Failed to create lock file %s\n", Lfile);
return 1;
}
gmtlib_file_lock (GMT, fileno(fp)); /* Attempt exclusive lock */
}
gmtlib_file_lock (GMT, fileno(fp)); /* Attempt exclusive lock */

if ((Curl = curl_easy_init ()) == NULL) {
GMT_Report (API, GMT_MSG_ERROR, "Failed to initiate curl\n");
Expand Down Expand Up @@ -1196,9 +1199,11 @@ int gmt_download_file (struct GMT_CTRL *GMT, const char *name, char *url, char *
if (urlfile.fp) /* close the local file */
fclose (urlfile.fp);

gmtlib_file_unlock (GMT, fileno(fp));
gmt_remove_file (GMT, Lfile);
gmt_M_str_free (Lfile);
if (!query) { /* Remove lock file after successful download */
gmtlib_file_unlock (GMT, fileno(fp));
gmt_remove_file (GMT, Lfile);
gmt_M_str_free (Lfile);
}

gmtremote_turn_off_ctrl_C_check ();

Expand Down