mirror of
https://github.com/curl/curl.git
synced 2026-07-28 04:23:07 +03:00
tool_operate: for -O, use "default" as filename when the URL has none
... or pick the last directory part from the path if available. Instead of returning error. Add test 690 and 691 to verify. Test 76 and 2036 no longer apply. Closes #13988
This commit is contained in:
parent
cb829f994d
commit
e26eefd9ce
8 changed files with 165 additions and 85 deletions
|
|
@ -1147,9 +1147,13 @@ static CURLcode single_transfer(struct GlobalConfig *global,
|
|||
break;
|
||||
}
|
||||
if(!*per->outfile && !config->content_disposition) {
|
||||
errorf(global, "Remote filename has no length");
|
||||
result = CURLE_WRITE_ERROR;
|
||||
break;
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ fail:
|
|||
*/
|
||||
CURLcode get_url_file_name(char **filename, const char *url)
|
||||
{
|
||||
const char *pc, *pc2;
|
||||
char *pc, *pc2;
|
||||
CURLU *uh = curl_url();
|
||||
char *path = NULL;
|
||||
CURLUcode uerr;
|
||||
|
|
@ -195,20 +195,29 @@ CURLcode get_url_file_name(char **filename, const char *url)
|
|||
uerr = curl_url_set(uh, CURLUPART_URL, url, CURLU_GUESS_SCHEME);
|
||||
if(!uerr) {
|
||||
uerr = curl_url_get(uh, CURLUPART_PATH, &path, 0);
|
||||
curl_url_cleanup(uh);
|
||||
uh = NULL;
|
||||
if(!uerr) {
|
||||
curl_url_cleanup(uh);
|
||||
int i;
|
||||
|
||||
pc = strrchr(path, '/');
|
||||
pc2 = strrchr(pc ? pc + 1 : path, '\\');
|
||||
if(pc2)
|
||||
pc = pc2;
|
||||
for(i = 0; i < 2; i++) {
|
||||
pc = strrchr(path, '/');
|
||||
pc2 = strrchr(pc ? pc + 1 : path, '\\');
|
||||
if(pc2)
|
||||
pc = pc2;
|
||||
if(pc && !pc[1] && !i) {
|
||||
/* if the path ends with slash, try removing the trailing one
|
||||
and get the last directory part */
|
||||
*pc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(pc)
|
||||
/* duplicate the string beyond the slash */
|
||||
pc++;
|
||||
else
|
||||
/* no slash => empty string */
|
||||
pc = "";
|
||||
pc = (char *)"";
|
||||
|
||||
*filename = strdup(pc);
|
||||
curl_free(path);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue