mirror of
https://github.com/curl/curl.git
synced 2026-08-14 13:03:44 +03:00
tool_cb_wrt: use "curl_response" if no file name in URL
Use the same fallback for content-disposition cases as for regular -O Add test692: verify -JO with URL without a file name Reported-by: Brian Inglis Fixes #14939 Closes #14940
This commit is contained in:
parent
89de543204
commit
0cfc7fcca1
6 changed files with 73 additions and 23 deletions
|
|
@ -54,14 +54,11 @@ bool tool_create_output_file(struct OutStruct *outs,
|
|||
{
|
||||
struct GlobalConfig *global;
|
||||
FILE *file = NULL;
|
||||
char *fname = outs->filename;
|
||||
const char *fname = outs->filename;
|
||||
DEBUGASSERT(outs);
|
||||
DEBUGASSERT(config);
|
||||
global = config->global;
|
||||
if(!fname || !*fname) {
|
||||
warnf(global, "Remote filename has no length");
|
||||
return FALSE;
|
||||
}
|
||||
DEBUGASSERT(fname && *fname);
|
||||
|
||||
if(config->file_clobber_mode == CLOBBER_ALWAYS ||
|
||||
(config->file_clobber_mode == CLOBBER_DEFAULT &&
|
||||
|
|
|
|||
|
|
@ -1158,21 +1158,12 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||
|
||||
if(!per->outfile) {
|
||||
/* extract the filename from the URL */
|
||||
result = get_url_file_name(&per->outfile, per->this_url);
|
||||
result = get_url_file_name(global, &per->outfile, per->this_url);
|
||||
if(result) {
|
||||
errorf(global, "Failed to extract a sensible filename"
|
||||
errorf(global, "Failed to extract a filename"
|
||||
" from the URL to use for storage");
|
||||
break;
|
||||
}
|
||||
if(!*per->outfile && !config->content_disposition) {
|
||||
free(per->outfile);
|
||||
per->outfile = strdup("curl_response");
|
||||
if(!per->outfile) {
|
||||
result = CURLE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
warnf(global, "No remote file name, uses \"%s\"", per->outfile);
|
||||
}
|
||||
}
|
||||
else if(state->urls) {
|
||||
/* fill '#1' ... '#9' terms from URL pattern */
|
||||
|
|
@ -1190,6 +1181,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||
break;
|
||||
}
|
||||
}
|
||||
DEBUGASSERT(per->outfile);
|
||||
|
||||
if(config->output_dir && *config->output_dir) {
|
||||
char *d = aprintf("%s/%s", config->output_dir, per->outfile);
|
||||
|
|
@ -1210,7 +1202,7 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||
break;
|
||||
}
|
||||
|
||||
if(per->outfile && config->skip_existing) {
|
||||
if(config->skip_existing) {
|
||||
struct_stat fileinfo;
|
||||
if(!stat(per->outfile, &fileinfo)) {
|
||||
/* file is present */
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "tool_cfgable.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_operhlp.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
#include "memdebug.h" /* keep this as LAST include */
|
||||
|
||||
|
|
@ -178,7 +179,8 @@ fail:
|
|||
* Returns a pointer to a heap-allocated string or NULL if
|
||||
* no name part, at location indicated by first argument.
|
||||
*/
|
||||
CURLcode get_url_file_name(char **filename, const char *url)
|
||||
CURLcode get_url_file_name(struct GlobalConfig *global,
|
||||
char **filename, const char *url)
|
||||
{
|
||||
CURLU *uh = curl_url();
|
||||
char *path = NULL;
|
||||
|
|
@ -212,9 +214,11 @@ CURLcode get_url_file_name(char **filename, const char *url)
|
|||
if(pc)
|
||||
/* duplicate the string beyond the slash */
|
||||
pc++;
|
||||
else
|
||||
/* no slash => empty string */
|
||||
pc = (char *)"";
|
||||
else {
|
||||
/* no slash => empty string, use default */
|
||||
pc = (char *)"curl_response";
|
||||
warnf(global, "No remote file name, uses \"%s\"", pc);
|
||||
}
|
||||
|
||||
*filename = strdup(pc);
|
||||
curl_free(path);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ bool stdin_upload(const char *uploadfile);
|
|||
|
||||
CURLcode add_file_name_to_url(CURL *curl, char **inurlp, const char *filename);
|
||||
|
||||
CURLcode get_url_file_name(char **filename, const char *url);
|
||||
CURLcode get_url_file_name(struct GlobalConfig *global,
|
||||
char **filename, const char *url);
|
||||
|
||||
CURLcode urlerr_cvt(CURLUcode ucode);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue