Skip to content

Commit 4080d37

Browse files
committed
NSData: fix an errno stomp
We would attempt to remove the temporary file. However, that will result in calls which can destroy the original errno. Save the previous errno before performing the cleanup.
1 parent 480caee commit 4080d37

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Foundation/NSData.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,9 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
517517
if let auxFilePath = auxFilePath {
518518
try fm._fileSystemRepresentation(withPath: auxFilePath, { auxFilePathFsRep in
519519
if rename(auxFilePathFsRep, pathFsRep) != 0 {
520+
let savedErrno = errno
520521
try? FileManager.default.removeItem(atPath: auxFilePath)
521-
throw _NSErrorWithErrno(errno, reading: false, path: path)
522+
throw _NSErrorWithErrno(savedErrno, reading: false, path: path)
522523
}
523524
if let mode = mode {
524525
chmod(pathFsRep, mode)

0 commit comments

Comments
 (0)