-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-93180: Update documentation of os.copy_file_range
#93182
Changes from 4 commits
c57e76f
23bbe3a
1e38126
caeb624
59561bf
bcb339d
069651d
f6152e4
94ef9cc
7ab57e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -798,18 +798,31 @@ as internal buffering of data. | |
Copy *count* bytes from file descriptor *src*, starting from offset | ||
*offset_src*, to file descriptor *dst*, starting from offset *offset_dst*. | ||
If *offset_src* is None, then *src* is read from the current position; | ||
respectively for *offset_dst*. The files pointed by *src* and *dst* | ||
respectively for *offset_dst*. | ||
|
||
In Linux kernel older than 5.3, the files pointed by *src* and *dst* | ||
must reside in the same filesystem, otherwise an :exc:`OSError` is | ||
raised with :attr:`~OSError.errno` set to :data:`errno.EXDEV`. | ||
|
||
This copy is done without the additional cost of transferring data | ||
from the kernel to user space and then back into the kernel. Additionally, | ||
some filesystems could implement extra optimizations. The copy is done as if | ||
some filesystems could implement extra optimizations, such as the use of | ||
reflinks (i.e., two or more inodes that share pointers to the same | ||
copy-on-write disk blocks; supported file systems include btrfs and XFS) | ||
and server-side copy (in the case of NFS). The copy is done as if | ||
both files are opened as binary. | ||
|
||
The return value is the amount of bytes copied. This could be less than the | ||
amount requested. | ||
|
||
.. note:: | ||
|
||
This function should not be used for copying a file from special | ||
filesystems like procfs and sysfs because of | ||
`a known issue <https://lore.kernel.org/linux-fsdevel/20210126135012.1.If45b7cdc3ff707bc1efa17f5366057d60603c45f@changeid/>`_. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link contains a fix. Was the fix merged into Linux? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it wasn't. I tested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, some Python functions that operate files are prone to similar issues too :(. I'll create a few bug reports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to not add a link to an email. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about such a note?
|
||
It will copy nothing and return 0 because file sizes there are not known | ||
to the system. | ||
|
||
.. availability:: Linux kernel >= 4.5 or glibc >= 2.27. | ||
|
||
.. versionadded:: 3.8 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update documentation of :func:`os.copy_file_range`. Patch by Illia Volochii. | ||
illia-v marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
The function arguments are file descriptors. What does "binary" mean for file descriptors?
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.
This sentence is not new. I guess it means that bytes written to a destination file will be equal to ones read from the source file.
In contrary, if a file range is read in the text mode in Python and it is written in the text mode to a different file, bytes may differ. For example, line endings may be changed. See https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files.
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.
Would you mind to rephase the sentence to explain that? Explain that the copy does not change the line endings, for example?
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.
Done 069651d.
BTW,
shutil.copyfile
looks to behave the same, butshutil.copyfileobj
seems to respect the text mode.