-
Notifications
You must be signed in to change notification settings - Fork 1.2k
NSData: Refactor write(toFile:options) using FileHandle methods. #1876
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 |
CC @compnerd @phausler @millenomi This is the first |
This definitely seems to be cleaning up a bunch of stuff. At the very least, some of this stuff is NFC, and you could split it off and merge those earlier (e.g the checkFileHandle and fileDescriptor variable refactorings). |
c170577
to
adc8f34
Compare
@swift-ci test |
@swift-ci test |
Foundation/FileHandle.swift
Outdated
} | ||
if BytesWritten == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be bytesWritten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - fixed.
adc8f34
to
9507ea6
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
Alright, this looks good to me. Not sure if @parkera @phausler @millenomi have had a chance to look this over yet. |
@parkera @phausler @millenomi - this is actually now blocking work on the Windows port. |
Please rebase this on the new API once that lands? There's a |
LGTM once rebased! |
- Remove makeTemporaryFile(inDirectory:) in favour of using _NSCreateTemporaryFile(path). - FileHandle: Add internal _writeBytes(buf:length) method to write out memory buffers. - FileManager: add _permissionsOfItem(atPath:) to only get permissions as it does less work than attributesOfItem(atPath:).
9507ea6
to
bb74cad
Compare
@swift-ci test |
@millenomi This has been rebased on top of the new FileHandle API. |
LGTM |
…ask` **Problem** `Data.write(to:)` is a only method in the Foundation that can create a regular file. However, it ignores `uamask` 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. JIRA: https://bugs.swift.org/browse/SR-13307
…ask` **Problem** `Data.write(to:)` is a only method in the Foundation that can create a regular file. However, it ignores `uamask` 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. JIRA: https://bugs.swift.org/browse/SR-13307
**Problem** `Data.write(to:)` is a only method in the Foundation that can create a regular file. However, it ignores `uamask` 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. JIRA: https://bugs.swift.org/browse/SR-13307
**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.
**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.
**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.
**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.
Remove makeTemporaryFile(inDirectory:) in favour of using
_NSCreateTemporaryFile(path).
FileHandle: Add internal _write(buf:length) method to write out memory
buffers.
FileHandle: Add a throwing _synchronizeFile(), use it in synchronizeFile().