-
Notifications
You must be signed in to change notification settings - Fork 2
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
Simple fix for github issue #3 #4
Conversation
This is a simple and not very clean fix for gridcf/issues/3 Either (one of) the l_write() or the l_close() can fail if the remote file already exists, since the data goes over a different channel than the control messages. For large files, it will typically be one of the later l_write() statements, for small files probably the l_close(). Hence we effectively only have the errmsg to find out what happened, and therefore do a simple str(n)cmp with this errmsg. For this we also need to add a function to get it from the opaque errcode_t.
cmds.c
Outdated
if (ec && strncmp(ec_get_errmsg(ec), "550 File exists", 15) == 0 || | ||
ecr && strncmp(ec_get_errmsg(ecr),"550 File exists", 15) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: should be more robust to compare against just the number. According to https://tools.ietf.org/html/rfc959 4.2, the reply is defined to be a 3-digit code followed by a space, but the text afterward can be anything.
if (ec && strncmp(ec_get_errmsg(ec), "550 File exists", 15) == 0 || | |
ecr && strncmp(ec_get_errmsg(ecr),"550 File exists", 15) == 0) | |
/* file exists */ | |
if (ec && strncmp(ec_get_errmsg(ec), "550 ", 4) == 0 || | |
ecr && strncmp(ec_get_errmsg(ecr),"550 ", 4) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had considered that, then thought not to since 550 is a bit more generic (there can be different reasons than that the file already exists in which can we might need to delete it after all), but I think you're right it's probably still the most reliable check now. I now check just on the 550+space (in case anyone ever would come up with error 5501) as you suggested.
I also am stil considering whether we should include other numbers, or perhaps even do the reverse: there are only a few cases in which we actually want to do the delete.
Ideally we should check beforehand whether the file exists and overwriting is not allowed, but the FEAT string is identical whether overwriting is allowed or not.
Better just check for the "550 " part than the whole error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msalle:
Is the current state of the patches up to date with what was discussed/decided in #3?
And do the changes work as expected during a test replicating the situation described in the original GGUS ticket?
No, this PR is still in the state where it would only NOT delete when the failure is a 550. For other failure modes it would still follow the code leading to the original deletion of the remote file.
Yes, I've extensively tested it with a locally built Uberftp from this branch and both prometheus.desy.de and gridftp.grid.sara.nl. |
@msalle: @matyasselmeci @ellert |
I'm closing this PR in favour of #5 |
This is a simple and not very clean fix for
/issues/3
Either (one of) the
l_write()
or thel_close()
can fail if the remote filealready exists, since the data goes over a different channel than the control
messages. For large files, it will typically be one of the later
l_write()
statements, for small files probably the
l_close()
. Hence we effectively onlyhave the
errmsg
to find out what happened, and therefore do a simplestr(n)cmp
with this
errmsg
. For this we also need to add a function to get it from theopaque
errcode_t
.Note that there are other FTP error codes that probably should prevent the delete.
Feedback on this would be highly appreciated (-;