Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect dir remembered on second MKD failure with CURLFTP_CREATE_DIR_RETRY #7967

Closed
youngr225 opened this issue Nov 5, 2021 · 1 comment
Assignees
Labels

Comments

@youngr225
Copy link
Contributor

youngr225 commented Nov 5, 2021

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",
@bagder bagder added the FTP label Nov 8, 2021
@bagder
Copy link
Member

bagder commented Nov 8, 2021

I think this would be much clearer if you would move the ftpc->count3 assignment to be just before MKD is sent (line ~3005), and only do it there.

Also, any chance you can make a "real" pull request out of this, or would you like me to do it for you?

@bagder bagder self-assigned this Nov 8, 2021
youngr225 added a commit to youngr225/curl that referenced this issue Nov 8, 2021
@bagder bagder closed this as completed in ef99e24 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants