adding ability to copy just a file from container to host#8362
adding ability to copy just a file from container to host#8362brahmaroutu wants to merge 1 commit intomoby:masterfrom
Conversation
|
what happens if they pass a directory with -f |
|
@jfrazelle Very good point. For destination, if a directory is specified, then it should try to copy the file to that directory, creating the path on its way(which is current behavior). Two ways to change the implementation. 1. It will be ideal to know if the source is a file or dir on the container before sending the request to the container avoiding overhead of transferring data. A bit unnecessary new functionality. 2. Detect if this is the last file in the stream received, io.ReadCloser does not let me peek but if -f is specified I can fetch the next file after the first file is fetched and expect it to be EOF and if that is not true, we can error out. I like the way code handles it today for directories(before and after my change). If at all I tend toward option 2 Examples (tested): Old behavior (-f is ignored) |
e4be8b1 to
8449513
Compare
8449513 to
fcb2d03
Compare
|
rebased, please see if this can be merged. |
|
I'm not sure about this. I thought that |
|
@LK4D4 I understand the concern but we have less of a choice to revert the behavior we have today (make cp file centric). I see current behavior is widely used in Docker Build and the builder. I thought adding explicit flag to work with single files is the only option. Please suggest if you think of an alternative approach that I can use to implement this. |
2e6a15c to
90e086d
Compare
docs/man/docker-cp.1.md
Outdated
90e086d to
8a95e37
Compare
|
@SvenDowideit When running the python script to update docs I believe it probably adds the commiters name to the history. |
|
@brahmaroutu sorry, the documentation in this PR does not tell the reader what the new flag does that is different to without it - that needs to be added to this PR. |
8a95e37 to
5685050
Compare
|
Should this be possible without having to add the flag? I.e.; I just think that this will act more according to user expectations; having to set a flag in order to copy a file just doesn't feel natural. |
|
I wanted to separate the current behavior, docker cp is directory bound, by adding a flag. The other way is to detect that the tar received from the container has a single file and logic can deal with it, this require complex changes as the current logic cannot read the tar twice(once to detect content and then stream). My implementation is explicit that user can tell me that he is copying a file that way we simply extend current 'cp' command. |
|
I'm with you on not trying to break BC. Would it be possible to have the daemon return a different response based on if the source was a file or a directory? Only able to comment from a user perspective as I lack the technical skills to oversee the technical requirements to achieve this. In short, if possible, I'd really prefer being able to copy a file without having to add a flag. |
|
I see your concern, changing the current signature/behavior of cp could be quite sensitive. I will have to explore other alternatives. |
|
Of course, given that the maintainers agree 😄 Thanks for investigating, much appreciated! |
|
We got a little explanation about the reasons for the I'll let @tiborvass and @unclejack look at the archive changes as they are the most familiar with that code. |
|
@crosbymichael If we have the ability to seek(pos) and reset on the pkg/ioutils/reader we can probably peek and detect the number of objects in the stream. If it has only one file then we can change the logic accordingly. This is more of a golang issue I guess. |
|
@brahmaroutu you can probably look at the tar headers to get the number of files that the tarstream contains. |
|
@brahmaroutu @crosbymichael sorry but this one is difficult to agree on the design. Let's make sure we first agree, and then update the PR. I don't like To be honest, I really think |
|
@tiborvass I agree, given the design, we cannot be automatically detect a file copy. Willing to change the implementation if you have better ideas. The golang tar does not have any meta data to see if a single file is in the archive and hence we rely on user letting us know that this is a single file copy. Changing the command name(cpm) may be another option? |
|
@brahmaroutu Like I said I don't want you to code unnecessarily, that's why I'd prefer we agree on the design first. Will add this to the list of things I'd like to discuss in the next design review session. |
|
@tiborvass yep, i was just commenting on I can see how it make sense here as to not break backwards compat because our first reflex was to say "we shouldn't need a flag at all". |
|
Just an FYI this totally works and I use it all the time.
I get the binary, one file in my cwd. |
|
I know the tar ball works fine for copying single files. We are addressing the scenario where |
|
Yes, from my example, i would mostly say that this is starting to look like a real bug and not something that we would need to work around to keep backwards compat. |
|
@crosbymichael if we decide it's a bug, I'm all for it! |
5685050 to
a4601db
Compare
a4601db to
8e42649
Compare
Addresses moby#4272 Signed-off-by: Srini Brahmaroutu <[email protected]>
8e42649 to
93ae505
Compare
|
I vote for treating it like a bug and fixing it in a new API version bump. If the client wants to use the old version (<= 1.16) then keep the old behavior. If the client uses a new api version (>= 1.17) then match the behavior of standard tools like |
|
Here's a summary of the current work I have at the other PR with general improvements to Improve
|
|
@brahmaroutu would you mind checking if #9871 fixes the issue. Then I think we can close this. Sorry for letting this linger for so long. |
|
@jfrazelle Yes, we should close this issue. I see #9871 is a complete solution, addresses many more missing pieces from the copy command. Great Job from @jlhawn. |
|
thanks so much :) |
Addresses #4272
Signed-off-by: Srini Brahmaroutu [email protected]