mirror of
https://github.com/curl/curl.git
synced 2026-07-30 20:18:08 +03:00
curl: add --create-file-mode [mode]
This option sets the (octal) mode to use for the remote file when one is created, using the SFTP, SCP or FILE protocols. When not set, the default is 0644. Closes #6244
This commit is contained in:
parent
e1a4647a42
commit
a7696c7343
10 changed files with 49 additions and 4 deletions
|
|
@ -193,6 +193,7 @@ struct OperationConfig {
|
|||
long ssl_version_max;
|
||||
long proxy_ssl_version;
|
||||
long ip_version;
|
||||
long create_file_mode; /* CURLOPT_NEW_FILE_PERMS */
|
||||
curl_TimeCond timecond;
|
||||
curl_off_t condtime;
|
||||
struct curl_slist *headers;
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ static const struct LongShort aliases[]= {
|
|||
#endif
|
||||
{"*q", "ftp-create-dirs", ARG_BOOL},
|
||||
{"*r", "create-dirs", ARG_BOOL},
|
||||
{"*R", "create-file-mode", ARG_STRING},
|
||||
{"*s", "max-redirs", ARG_STRING},
|
||||
{"*t", "proxy-ntlm", ARG_BOOL},
|
||||
{"*u", "crlf", ARG_BOOL},
|
||||
|
|
@ -774,6 +775,12 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
|
|||
config->create_dirs = toggle;
|
||||
break;
|
||||
|
||||
case 'R': /* --create-file-mode */
|
||||
err = oct2nummax(&config->create_file_mode, nextarg, 0777);
|
||||
if(err)
|
||||
return err;
|
||||
break;
|
||||
|
||||
case 's': /* --max-redirs */
|
||||
/* specified max no of redirects (http(s)), this accepts -1 as a
|
||||
special condition */
|
||||
|
|
|
|||
|
|
@ -181,6 +181,9 @@ static const struct helptxt helptext[] = {
|
|||
{" --create-dirs",
|
||||
"Create necessary local directory hierarchy",
|
||||
CURLHELP_CURL},
|
||||
{" --create-file-mode",
|
||||
"File mode for created files",
|
||||
CURLHELP_SFTP | CURLHELP_SCP | CURLHELP_FILE},
|
||||
{" --crlf",
|
||||
"Convert LF to CRLF in upload",
|
||||
CURLHELP_FTP | CURLHELP_SMTP},
|
||||
|
|
|
|||
|
|
@ -129,14 +129,13 @@ void cleanarg(char *str)
|
|||
* getparameter a lot, we must check it for NULL before accessing the str
|
||||
* data.
|
||||
*/
|
||||
|
||||
ParameterError str2num(long *val, const char *str)
|
||||
static ParameterError getnum(long *val, const char *str, int base)
|
||||
{
|
||||
if(str) {
|
||||
char *endptr = NULL;
|
||||
long num;
|
||||
errno = 0;
|
||||
num = strtol(str, &endptr, 10);
|
||||
num = strtol(str, &endptr, base);
|
||||
if(errno == ERANGE)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
if((endptr != str) && (endptr == str + strlen(str))) {
|
||||
|
|
@ -147,6 +146,24 @@ ParameterError str2num(long *val, const char *str)
|
|||
return PARAM_BAD_NUMERIC; /* badness */
|
||||
}
|
||||
|
||||
ParameterError str2num(long *val, const char *str)
|
||||
{
|
||||
return getnum(val, str, 10);
|
||||
}
|
||||
|
||||
ParameterError oct2nummax(long *val, const char *str, long max)
|
||||
{
|
||||
ParameterError result = getnum(val, str, 8);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
else if(*val > max)
|
||||
return PARAM_NUMBER_TOO_LARGE;
|
||||
else if(*val < 0)
|
||||
return PARAM_NEGATIVE_NUMERIC;
|
||||
|
||||
return PARAM_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse the string and write the long in the given address. Return PARAM_OK
|
||||
* on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
|
||||
|
|
@ -158,7 +175,7 @@ ParameterError str2num(long *val, const char *str)
|
|||
|
||||
ParameterError str2unum(long *val, const char *str)
|
||||
{
|
||||
ParameterError result = str2num(val, str);
|
||||
ParameterError result = getnum(val, str, 10);
|
||||
if(result != PARAM_OK)
|
||||
return result;
|
||||
if(*val < 0)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ void cleanarg(char *str);
|
|||
|
||||
ParameterError str2num(long *val, const char *str);
|
||||
ParameterError str2unum(long *val, const char *str);
|
||||
ParameterError oct2nummax(long *val, const char *str, long max);
|
||||
ParameterError str2unummax(long *val, const char *str, long max);
|
||||
ParameterError str2udouble(double *val, const char *str, long max);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue