Skip to content
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

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

Open
niw opened this issue Jul 28, 2020 · 2 comments

Comments

@niw
Copy link
Contributor

niw commented Jul 28, 2020

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.

@niw
Copy link
Contributor Author

niw commented Jul 28, 2020

Probably this is a bug introduced by
#1876
The original code is using 0666 for mode to open(2) but it changed to 0600.
cc: @spevans

@niw
Copy link
Contributor Author

niw commented Aug 14, 2020

The patch is available at #2851

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant