]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: add --create-file-mode [mode]
authorDaniel Stenberg <daniel@haxx.se>
Sun, 20 Dec 2020 17:44:20 +0000 (18:44 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 21 Dec 2020 09:52:41 +0000 (10:52 +0100)
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

docs/cmdline-opts/Makefile.inc
docs/cmdline-opts/create-file-mode.d [new file with mode: 0644]
docs/options-in-versions
src/tool_cfgable.h
src/tool_getparam.c
src/tool_help.c
src/tool_paramhlp.c
src/tool_paramhlp.h
tests/data/test1463
tests/data/test1464

index 097be34b6f5ce9acde81b9611c41b264e2d8a43e..059002a4e635f24f272952972bd1f4ed9659347e 100644 (file)
@@ -40,6 +40,7 @@ DPAGES =                                      \
   cookie-jar.d                                 \
   cookie.d                                     \
   create-dirs.d                                        \
+  create-file-mode.d                            \
   crlf.d crlfile.d                             \
   curves.d                                     \
   data-ascii.d                                 \
diff --git a/docs/cmdline-opts/create-file-mode.d b/docs/cmdline-opts/create-file-mode.d
new file mode 100644 (file)
index 0000000..115bacf
--- /dev/null
@@ -0,0 +1,12 @@
+Long: create-file-mode
+Help: File mode for created files
+Protocols: SFTP SCP FILE
+Category: sftp scp file upload
+See-also: ftp-create-dirs
+Added: 7.75.0
+---
+When curl is used to create files remotely using one of the supported
+protocols, this option allows the user to set which 'mode' to set on the file
+at creation time, instead of the default 0644.
+
+This options takes an octal number as argument.
index 97c416d830f36e19b4154b2c6eb1946b2b51850a..bb2de4614b9f7120b88862dde875fb5d99e8f7f1 100644 (file)
@@ -30,6 +30,7 @@
 --cookie (-b)                        4.9
 --cookie-jar (-c)                    7.9
 --create-dirs                        7.10.3
+--create-file-mode                   7.75.0
 --crlf                               5.7
 --crlfile                            7.19.7
 --curves                             7.73.0
index 6b7f874e12885b9bea6b9d578d63dfc0d2942c8d..dc1c5e557cbb134e8d99fc6383b1d3335f32f568 100644 (file)
@@ -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;
index b7cfeb62ecb8be35348aed0911ccfd1e1c671b1b..c57506609b11177c2855d96faf20239cbfaca777 100644 (file)
@@ -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 */
index a3323cd59092306959758c6eaa576cba595ed1cd..c78f98fa954454587b3f8700ed4b2922145dcaf1 100644 (file)
@@ -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},
index 2f43932ecf40173154bd9143e913fa57899f0511..a2f20cb17c697328346299eea846dbf95dd4f49b 100644 (file)
@@ -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)
index 664c8b0f591129bd07acc604d8578b08a167524a..32b0fc49b01199ecaaecc9bc346f02683b3b241d 100644 (file)
@@ -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);
 
index 7e1fe9b84099363f52c126b4e65d614d4f6c08b6..224bedab42c790139eacede03e8d4656a54aeb1c 100644 (file)
@@ -37,6 +37,7 @@ curl file category --help
 <stdout mode="text">
 Usage: curl [options...] <url>
 file: FILE protocol options
+     --create-file-mode File mode for created files
  -I, --head          Show document info only
  -r, --range <range> Retrieve only the bytes within RANGE
 </stdout>
index 167e80d6d5ff69ab93b0f1df16831da7e263bef9..774147517958006f8f707f5289a7685b5afbc666 100644 (file)
@@ -37,6 +37,7 @@ curl file category --help with lower/upper mix
 <stdout mode="text">
 Usage: curl [options...] <url>
 file: FILE protocol options
+     --create-file-mode File mode for created files
  -I, --head          Show document info only
  -r, --range <range> Retrieve only the bytes within RANGE
 </stdout>