Skip to content

Incorrect dir remembered on second MKD failure with CURLFTP_CREATE_DIR_RETRY #7967

Description

@youngr225

I did this

Simultaneous file transfer to same directory using curl_multi and CURLFTP_CREATE_DIR_RETRY.

I expected the following

Second MKD failure stores last successful CWD path in ftpc->prevpath.

> CWD 1
< 250 Directory successfully changed.
> CWD 2
< 550 Failed to change directory.
> MKD 2
< 550 Create directory operation failed.
> CWD 2
< 250 Directory successfully changed.
> CWD 3
< 550 Failed to change directory.
> MKD 3
< 550 Create directory operation failed.
* Failed to MKD dir: 550
* Remembering we are in dir "/ftp_root/1/2/3/"            # should not contain final 3 dir
* Uploaded unaligned file size (0 out of 351272 bytes)
* Connection #5 to host xxxx left intact

curl/libcurl version

7.72.0

operating system

openSUSE 15.2
Linux linux-jxih 5.3.18-lp152.95-default #1 SMP Tue Oct 5 07:30:50 UTC 2021 (7cfc6af) x86_64 x86_64 x86_64 GNU/Linux

proposed patch

Change behavior to allow one MKD failure per directory.

diff --git a/lib/ftp.c b/lib/ftp.c
index 0b9c9b73..db713fdd 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -876,9 +876,9 @@ static CURLcode ftp_state_cwd(struct Curl_easy *data,
 
     ftpc->count2 = 0; /* count2 counts failed CWDs */
 
-    /* count3 is set to allow a MKD to fail once. In the case when first CWD
-       fails and then MKD fails (due to another session raced it to create the
-       dir) this then allows for a second try to CWD to it */
+    /* count3 is set to allow a MKD to fail once per dir. In the case when the
+       first CWD fails and then MKD fails (due to another session raced it to
+       create the dir) this then allows for a second try to CWD to it */
     ftpc->count3 = (data->set.ftp_create_missing_dirs == 2)?1:0;
 
     if(conn->bits.reuse && ftpc->entrypath &&
@@ -3018,6 +3018,7 @@ static CURLcode ftp_statemachine(struct Curl_easy *data,
       else {
         /* success */
         ftpc->count2 = 0;
+        ftpc->count3 = (data->set.ftp_create_missing_dirs == 2) ? 1 : 0;
         if(++ftpc->cwdcount <= ftpc->dirdepth)
           /* send next CWD */
           result = Curl_pp_sendf(data, &ftpc->pp, "CWD %s",

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions