Skip to content

fs::copy() does not handle sparse files #58635

Closed
@haraldh

Description

@haraldh
Contributor

A convenience method like fs::copy() should try to prevent pitfalls a
normal user doesn't think about.

Not handling sparse files could fill up the users disk very quickly.

In case of an empty umask, setting the file mode early prevents
temporarily world readable or even writeable files,
because the default mode is 0o666.

In case the target is a named pipe or special device node, setting the
file mode can lead to unwanted side effects, like setting permissons on
/dev/stdout or for root setting permissions on /dev/null.

See also
#26933
#37885

Activity

haraldh

haraldh commented on Feb 22, 2019

@haraldh
ContributorAuthor

see #58636 for the fix

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Feb 22, 2019
Mark-Simulacrum

Mark-Simulacrum commented on Dec 23, 2019

@Mark-Simulacrum
Member

I believe we've decided that sparse files are not something we want to handle; the file mode and special device issue we've fixed. Closing.

avirtuos

avirtuos commented on Mar 3, 2022

@avirtuos

@Mark-Simulacrum I realize this is an old issue but can you share some insights into why it was decided that sparse files are not something you want to handle? There are a few growing rust projects related to VMMs like ( https://github.com/firecracker-microvm/firecracker ) that are built largely with rust and frequently trip over this limitation.

Mark-Simulacrum

Mark-Simulacrum commented on Mar 3, 2022

@Mark-Simulacrum
Member

Likely largely based on discussion in #55909 and #58636, though it's been some time since then. Feel free to drop by #t-libs on Zulip and ask for folks opinions now.

(It may also be that the necessary work to make this happen is easier now, if the kernel APIs have simplified somewhat).

avirtuos

avirtuos commented on Mar 4, 2022

@avirtuos

@Mark-Simulacrum thanks, will follow up as you suggest after reading those items.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haraldh@Centril@Mark-Simulacrum@avirtuos

        Issue actions

          fs::copy() does not handle sparse files · Issue #58635 · rust-lang/rust