From f5028cea2e66903fb8d80e312995a7252c90aace Mon Sep 17 00:00:00 2001 From: Kevin Perry Date: Thu, 20 Mar 2025 19:09:03 -0700 Subject: [PATCH] rdar://138657153 (Writing NSData atomically defaults to using noFileProtection (class D)) --- Sources/FoundationEssentials/Data/Data+Writing.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/FoundationEssentials/Data/Data+Writing.swift b/Sources/FoundationEssentials/Data/Data+Writing.swift index 90ebd8628..fa05b2ca0 100644 --- a/Sources/FoundationEssentials/Data/Data+Writing.swift +++ b/Sources/FoundationEssentials/Data/Data+Writing.swift @@ -226,12 +226,14 @@ private func createProtectedTemporaryFile(at destinationPath: String, inPath: Pa } } + let updatedOptions = _NSDataWritingOptionsForRelocatedAtomicWrite(options, destinationPath) + let auxFile = temporaryDirectoryPath.appendingPathComponent(destinationPath.lastPathComponent) return try auxFile.withFileSystemRepresentation { auxFileFileSystemRep in guard let auxFileFileSystemRep else { throw CocoaError(.fileWriteInvalidFileName) } - let fd = openFileDescriptorProtected(path: auxFileFileSystemRep, flags: O_CREAT | O_EXCL | O_RDWR, options: options) + let fd = openFileDescriptorProtected(path: auxFileFileSystemRep, flags: O_CREAT | O_EXCL | O_RDWR, options: updatedOptions) if fd >= 0 { return (fd, auxFile, temporaryDirectoryPath) } else {