Skip to content

Commit 3179457

Browse files
authored
rdar://138657153 (Writing NSData atomically defaults to using noFileProtection (class D)) (#1223)
1 parent 4ce93ac commit 3179457

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Sources/FoundationEssentials/Data/Data+Writing.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ private func createProtectedTemporaryFile(at destinationPath: String, inPath: Pa
226226
}
227227
}
228228

229+
let updatedOptions = _NSDataWritingOptionsForRelocatedAtomicWrite(options, destinationPath)
230+
229231
let auxFile = temporaryDirectoryPath.appendingPathComponent(destinationPath.lastPathComponent)
230232
return try auxFile.withFileSystemRepresentation { auxFileFileSystemRep in
231233
guard let auxFileFileSystemRep else {
232234
throw CocoaError(.fileWriteInvalidFileName)
233235
}
234-
let fd = openFileDescriptorProtected(path: auxFileFileSystemRep, flags: O_CREAT | O_EXCL | O_RDWR, options: options)
236+
let fd = openFileDescriptorProtected(path: auxFileFileSystemRep, flags: O_CREAT | O_EXCL | O_RDWR, options: updatedOptions)
235237
if fd >= 0 {
236238
return (fd, auxFile, temporaryDirectoryPath)
237239
} else {

0 commit comments

Comments
 (0)