-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Create a file with permissions that respects umask #2858
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
Conversation
@swift-ci test |
It looks like this was just heavy traffic triggering the type evaluation timeout. |
@swift-ci please test |
Hmm, intersting... |
Oh, no, |
d01bd2f
to
8fa17ed
Compare
@swift-ci please test |
Ugh, multi-platform change isn't easy really. |
**Problem** `Data.write(to:)` is a only method in the Foundation that can create a regular file. However, it ignores `umask` and always set 0600 permission unlike macOS Foundation, which respects process `umask`. **Solution** 1. With `.atomic` write option It uses `mkstemp(3)` in `_NSCreateTemporaryFile`, which is always creating a file with 0600 permission, if the system follows the latest POSIX specification or the permission is undefined. On macOS Foundation, therefore `_NSCreateTemporaryFile` uses `mktemp(3)` and `open(2)` instead to respect `umask`. 2. Without `.atomic` write option It uses `0o600` even if it uses `open(2)` that respects `umask`. Simply gives `0o666` instead. This is a bug caused by previous commit in swiftlang#1876. Swift JIRA is https://bugs.swift.org/browse/SR-13307.
9058f72
to
2c8ff0a
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
Hmm... both CI failed on different position and... seems unrelated to the patch itself...? 🤔 |
@swift-ci please test |
Problem
Data.write(to:)
is a only method in the Foundation that can create aregular file.
However, it ignores
umask
and always set 0600 permission unlikemacOS Foundation, which respects process
umask
.Solution
With
.atomic
write optionIt uses
mkstemp(3)
in_NSCreateTemporaryFile
, which is alwayscreating a file with 0600 permission, if the system follows
the latest POSIX specification or the permission is undefined.
On macOS Foundation, therefore
_NSCreateTemporaryFile
usesmktemp(3)
andopen(2)
instead to respectumask
.Without
.atomic
write optionIt uses
0o600
even if it usesopen(2)
that respectsumask
.Simply gives
0o666
instead.This is a bug caused by previous commit in
#1876.
Swift JIRA is https://bugs.swift.org/browse/SR-13307.