Skip to content

[SR-13307] Default mode to open(2) is not same between Foundation and corelibs Foundation #3247

@niw

Description

@niw
Previous ID SR-13307
Radar None
Original Reporter @niw
Type Bug
Environment

macOS 10.15.6
Ubuntu 18.04 (Official swift:latest Docker image)

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 915184f699d2e0392da90f9a7be55035

Issue Description:

For example, with following code, users expected to create a new file (if it doesn’t exist) with permission that respects current umask.

import Foundation
try! Data().write(to: URL(fileURLWithPath: "file"))

On macOS, In case umask is 022, it creates file with permission 0644 on macOS.
in case umask is 0, it creates file with permission 0666.
Therefore, default mode to open(2) seems having 0666.

However, on Linux, since corelibs Foundation is using default mode 0600 to open(2) (called via _CFOpenFileWithMode()), in case umask is 022, it creates file with permission 0600 instead of 0644.
https://github.com/apple/swift-corelibs-foundation/blame/master/Sources/Foundation/NSData.swift#L438

This behavior's inconsistency surprising Foundation library users.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions