Skip to content

A curious case of copyFile #11437

@Bodigrim

Description

@Bodigrim

I’m trying to decipher the expected semantics of Distribution.Compat.CopyFile.copyFile and how it differs from the usual System.Directory.copyFile. It seems like Unix and Windows implementations lean into opposite directions: the Unix one makes an effort to copy less metadata than System.Directory.copyFile and the Windows one copies as much as possible.

The module was introduced in 6d24556:

Author: Duncan Coutts <[email protected]>
Date:   Wed Jan 28 18:11:15 2009 +0000

    Add Distribution.Compat.CopyFile module
    This is to work around the file permissions problems with the
    standard System.Directory.copyFile function. When installing
    files we do not want to copy permissions or attributes from the
    source files. On unix we want to use specific permissions and
    on windows we want to inherit default permissions. On unix:
    copyOrdinaryFile   sets the permissions to -rw-r--r--
    copyExecutableFile sets the permissions to -rwxr-xr-x

At that point the implementation was the same both for Unix and Windows: just open file handles and copy data manually block by block. Indeed no inheritance of permissions or attributes happens, which differs from System.Directory.copyFile (it copies user, group and permission bits).

I’m not sure what’s the harm with copying this metadata though that it justifies rolling out a manual implementation?.. I’d imagine we can copy it and then adjust permissions bits as we see fit?.. CC @dcoutts

The plot thickens though, because of d8b6a24

Author: Tamar Christina <[email protected]>
Date:   Mon Dec 25 17:49:13 2017 +0000

    Cabal: Add support on Windows for copying to long paths.

At this point Distribution.Compat.CopyFile.copyFile gained a Windows-specific implementation, capable to deal with longer file paths. The thing is however that Win32 API call Win32.copyFile copies as much metadata as possible, including not only owners and permissions, but also, say, creation / modification times. (This is the same call as used by System.Directory.copyFileWithMetadata) This seems to be very much opposite to the original intention of Distribution.Compat.CopyFile.copyFile. Yet no one complained in the past 9 years, so it’s probably not a real concern?..

I’m tempted for the sake of simplicity to follow the same pattern on Unix: copy files using System.Directory.copyFile and adjust permissions later. Are there any tangible downsides to it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions