Skip to content

Commit 0b6e6eb

Browse files
committed
2 parents aebd254 + c82e1de commit 0b6e6eb

18 files changed

+57
-157
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ add_swift_library(Foundation
302302
$<$<PLATFORM_ID:Windows>:-lWS2_32>
303303
$<$<PLATFORM_ID:Windows>:-liphlpapi>
304304
$<$<PLATFORM_ID:Windows>:-lpathcch>
305+
$<$<PLATFORM_ID:Windows>:$<TARGET_OBJECTS:CoreFoundationResources>>
305306
SWIFT_FLAGS
306307
-DDEPLOYMENT_RUNTIME_SWIFT
307308
${deployment_enable_libdispatch}

CoreFoundation/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ add_framework(CoreFoundation
205205
URL.subproj/CFURLAccess.h
206206
URL.subproj/CFURLComponents.h
207207
SOURCES
208-
$<$<PLATFORM_ID:Windows>:CoreFoundation.rc>
209208
# Base
210209
Base.subproj/CFBase.c
211210
Base.subproj/CFFileUtilities.c
@@ -317,6 +316,14 @@ add_framework(CoreFoundation
317316
URL.subproj/CFURLComponents_URIParser.c
318317
URL.subproj/CFURLSessionInterface.c)
319318
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
319+
add_library(CoreFoundationResources OBJECT
320+
CoreFoundation.rc)
321+
if(BUILD_SHARED_LIBS)
322+
target_link_libraries(CoreFoundation PRIVATE CoreFoundationResources)
323+
else()
324+
target_link_libraries(CoreFoundation INTERFACE CoreFoundationResources)
325+
endif()
326+
320327
# NOTE(compnerd) the WindowsOlsonMapping.plist and OlsonWindowsMapping.plist
321328
# are embedded Windows resources that we use to map the Windows timezone to
322329
# the Olson name. Ensure that we rebuild on regeneration of the files.

Foundation/FileManager+Win32.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ extension FileManager {
329329
var faAttributes: WIN32_FILE_ATTRIBUTE_DATA = WIN32_FILE_ATTRIBUTE_DATA()
330330
do { faAttributes = try windowsFileAttributes(atPath: srcPath) } catch { return }
331331

332-
var fileType = FileAttributeType(attributes: faAttributes)
332+
var fileType = FileAttributeType(attributes: faAttributes, atPath: srcPath)
333333
if fileType == .typeDirectory {
334334
try createDirectory(atPath: dstPath, withIntermediateDirectories: false, attributes: nil)
335335
guard let enumerator = enumerator(atPath: srcPath) else {
@@ -341,7 +341,7 @@ extension FileManager {
341341
let dst = joinPath(prefix: dstPath, suffix: item)
342342

343343
do { faAttributes = try windowsFileAttributes(atPath: src) } catch { return }
344-
fileType = FileAttributeType(attributes: faAttributes)
344+
fileType = FileAttributeType(attributes: faAttributes, atPath: srcPath)
345345
if fileType == .typeDirectory {
346346
try createDirectory(atPath: dst, withIntermediateDirectories: false, attributes: nil)
347347
} else {

Foundation/FileManager.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ open class FileManager : NSObject {
361361

362362
#if os(Windows)
363363
result[.deviceIdentifier] = NSNumber(value: UInt64(s.st_rdev))
364-
let type = FileAttributeType(attributes: try windowsFileAttributes(atPath: path))
364+
let type = FileAttributeType(attributes: try windowsFileAttributes(atPath: path), atPath: path)
365365
#else
366366
if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil {
367367
let name = String(cString: pwd.pointee.pw_name)
@@ -884,14 +884,6 @@ public struct FileAttributeKey : RawRepresentable, Equatable, Hashable {
884884
self.rawValue = rawValue
885885
}
886886

887-
public func hash(into hasher: inout Hasher) {
888-
hasher.combine(rawValue)
889-
}
890-
891-
public static func ==(_ lhs: FileAttributeKey, _ rhs: FileAttributeKey) -> Bool {
892-
return lhs.rawValue == rhs.rawValue
893-
}
894-
895887
public static let type = FileAttributeKey(rawValue: "NSFileType")
896888
public static let size = FileAttributeKey(rawValue: "NSFileSize")
897889
public static let modificationDate = FileAttributeKey(rawValue: "NSFileModificationDate")
@@ -928,27 +920,34 @@ public struct FileAttributeType : RawRepresentable, Equatable, Hashable {
928920
self.rawValue = rawValue
929921
}
930922

931-
public func hash(into hasher: inout Hasher) {
932-
hasher.combine(rawValue)
933-
}
934-
935-
public static func ==(_ lhs: FileAttributeType, _ rhs: FileAttributeType) -> Bool {
936-
return lhs.rawValue == rhs.rawValue
937-
}
938-
939923
#if os(Windows)
940-
internal init(attributes: WIN32_FILE_ATTRIBUTE_DATA) {
924+
internal init(attributes: WIN32_FILE_ATTRIBUTE_DATA, atPath path: String) {
941925
if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY) == DWORD(FILE_ATTRIBUTE_DIRECTORY) {
942926
self = .typeDirectory
943927
} else if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DEVICE) == DWORD(FILE_ATTRIBUTE_DEVICE) {
944928
self = .typeCharacterSpecial
945929
} else if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_REPARSE_POINT) == DWORD(FILE_ATTRIBUTE_REPARSE_POINT) {
946-
// FIXME(compnerd) this is a lie! It may be a junction or a hard link
947-
self = .typeSymbolicLink
948-
} else if attributes.dwFileAttributes & DWORD(FILE_ATTRIBUTE_NORMAL) == DWORD(FILE_ATTRIBUTE_NORMAL) {
949-
self = .typeRegular
930+
// A reparse point may or may not actually be a symbolic link, we need to read the reparse tag
931+
let fileHandle = path.withCString(encodedAs: UTF16.self) {
932+
CreateFileW(/*lpFileName=*/$0,
933+
/*dwDesiredAccess=*/DWORD(0),
934+
/*dwShareMode=*/DWORD(FILE_SHARE_READ | FILE_SHARE_WRITE),
935+
/*lpSecurityAttributes=*/nil,
936+
/*dwCreationDisposition=*/DWORD(OPEN_EXISTING),
937+
/*dwFlagsAndAttributes=*/DWORD(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS),
938+
/*hTemplateFile=*/nil)
939+
}
940+
var tagInfo = FILE_ATTRIBUTE_TAG_INFO()
941+
guard 0 != GetFileInformationByHandleEx(fileHandle,
942+
FileAttributeTagInfo,
943+
&tagInfo,
944+
DWORD(MemoryLayout<FILE_ATTRIBUTE_TAG_INFO>.size)) else {
945+
self = .typeUnknown
946+
return
947+
}
948+
self = tagInfo.ReparseTag == IO_REPARSE_TAG_SYMLINK ? .typeSymbolicLink : .typeRegular
950949
} else {
951-
self = .typeUnknown
950+
self = .typeRegular
952951
}
953952
}
954953
#else

Foundation/HTTPCookie.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable {
1717
public init(rawValue: String) {
1818
self.rawValue = rawValue
1919
}
20-
21-
public func hash(into hasher: inout Hasher) {
22-
hasher.combine(rawValue)
23-
}
24-
25-
public static func ==(_ lhs: HTTPCookiePropertyKey, _ rhs: HTTPCookiePropertyKey) -> Bool {
26-
return lhs.rawValue == rhs.rawValue
27-
}
2820
}
2921

3022
extension HTTPCookiePropertyKey {

Foundation/NSAttributedString.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ extension NSAttributedString {
2020
public init(rawValue: String) {
2121
self.rawValue = rawValue
2222
}
23-
24-
public func hash(into hasher: inout Hasher) {
25-
hasher.combine(rawValue)
26-
}
27-
28-
public static func ==(left: NSAttributedString.Key, right: NSAttributedString.Key) -> Bool {
29-
return left.rawValue == right.rawValue
30-
}
3123
}
3224
}
3325

Foundation/NSCalendar.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ extension NSCalendar {
6666
self.rawValue = rawValue
6767
}
6868

69-
public func hash(into hasher: inout Hasher) {
70-
hasher.combine(rawValue)
71-
}
72-
7369
public static let gregorian = NSCalendar.Identifier("gregorian")
7470
public static let buddhist = NSCalendar.Identifier("buddhist")
7571
public static let chinese = NSCalendar.Identifier("chinese")
@@ -137,10 +133,6 @@ extension NSCalendar {
137133
}
138134

139135
extension NSCalendar.Identifier {
140-
public static func ==(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
141-
return lhs.rawValue == rhs.rawValue
142-
}
143-
144136
public static func <(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
145137
return lhs.rawValue < rhs.rawValue
146138
}

Foundation/NSDecimalNumber.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public struct NSExceptionName : RawRepresentable, Equatable, Hashable {
1818
public init(rawValue: String) {
1919
self.rawValue = rawValue
2020
}
21-
22-
public func hash(into hasher: inout Hasher) {
23-
hasher.combine(rawValue)
24-
}
25-
26-
public static func ==(_ lhs: NSExceptionName, _ rhs: NSExceptionName) -> Bool {
27-
return lhs.rawValue == rhs.rawValue
28-
}
2921
}
3022

3123
extension NSExceptionName {

Foundation/NSLocale.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ extension NSLocale {
177177
self.rawValue = rawValue
178178
}
179179

180-
public func hash(into hasher: inout Hasher) {
181-
hasher.combine(rawValue)
182-
}
183-
184180
public static let identifier = NSLocale.Key(rawValue: "kCFLocaleIdentifierKey")
185181
public static let languageCode = NSLocale.Key(rawValue: "kCFLocaleLanguageCodeKey")
186182
public static let countryCode = NSLocale.Key(rawValue: "kCFLocaleCountryCodeKey")
@@ -213,13 +209,6 @@ extension NSLocale {
213209
}
214210

215211

216-
extension NSLocale.Key {
217-
public static func ==(_ lhs: NSLocale.Key, _ rhs: NSLocale.Key) -> Bool {
218-
return lhs.rawValue == rhs.rawValue
219-
}
220-
}
221-
222-
223212
extension NSLocale {
224213
public static let currentLocaleDidChangeNotification = NSNotification.Name(rawValue: "kCFLocaleCurrentLocaleDidChangeNotification")
225214
}

Foundation/NSNotification.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ open class NSNotification: NSObject, NSCopying, NSCoding {
1313
public init(rawValue: String) {
1414
self.rawValue = rawValue
1515
}
16-
17-
public func hash(into hasher: inout Hasher) {
18-
hasher.combine(rawValue)
19-
}
20-
21-
public static func ==(lhs: Name, rhs: Name) -> Bool {
22-
return lhs.rawValue == rhs.rawValue
23-
}
2416
}
2517

2618
private(set) open var name: Name

Foundation/NSString.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ extension NSString {
115115

116116
public let rawValue: String
117117

118-
public var hashValue: Int {
119-
return self.rawValue.hashValue
120-
}
121-
122-
public static func ==(_ lhs: StringTransform, _ rhs: StringTransform) -> Bool {
123-
return lhs.rawValue == rhs.rawValue
124-
}
125-
126118
public init(_ rawValue: String) {
127119
self.rawValue = rawValue
128120
}

Foundation/NSURL.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,6 @@ public struct URLResourceKey : RawRepresentable, Equatable, Hashable {
7575
public init(_ rawValue: String) {
7676
self.rawValue = rawValue
7777
}
78-
79-
public func hash(into hasher: inout Hasher) {
80-
hasher.combine(rawValue)
81-
}
82-
83-
public static func ==(lhs: URLResourceKey, rhs: URLResourceKey) -> Bool {
84-
return lhs.rawValue == rhs.rawValue
85-
}
8678
}
8779

8880
extension URLResourceKey {
@@ -197,14 +189,6 @@ public struct URLFileResourceType : RawRepresentable, Equatable, Hashable {
197189
public init(_ rawValue: String) {
198190
self.rawValue = rawValue
199191
}
200-
201-
public func hash(into hasher: inout Hasher) {
202-
hasher.combine(rawValue)
203-
}
204-
205-
public static func ==(lhs: URLFileResourceType, rhs: URLFileResourceType) -> Bool {
206-
return lhs.rawValue == rhs.rawValue
207-
}
208192
}
209193

210194
extension URLFileResourceType {

Foundation/Progress.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,7 @@ open class Progress : NSObject {
399399
public let rawValue: String
400400
public init(_ rawValue: String) { self.rawValue = rawValue }
401401
public init(rawValue: String) { self.rawValue = rawValue }
402-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
403-
public static func ==(_ lhs: FileOperationKind, _ rhs: FileOperationKind) -> Bool { return lhs.rawValue == rhs.rawValue }
404-
402+
405403
/// Use for indicating the progress represents a download.
406404
public static let downloading = FileOperationKind(rawValue: "NSProgressFileOperationKindDownloading")
407405

@@ -478,9 +476,7 @@ public struct ProgressKind : RawRepresentable, Equatable, Hashable {
478476
public let rawValue: String
479477
public init(_ rawValue: String) { self.rawValue = rawValue }
480478
public init(rawValue: String) { self.rawValue = rawValue }
481-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
482-
public static func ==(_ lhs: ProgressKind, _ rhs: ProgressKind) -> Bool { return lhs.rawValue == rhs.rawValue }
483-
479+
484480
/// Indicates that the progress being performed is related to files.
485481
///
486482
/// Progress of this kind is assumed to use bytes as the unit of work being done and the default implementation of `localizedDescription` takes advantage of that to return more specific text than it could otherwise.
@@ -491,9 +487,7 @@ public struct ProgressUserInfoKey : RawRepresentable, Equatable, Hashable {
491487
public let rawValue: String
492488
public init(_ rawValue: String) { self.rawValue = rawValue }
493489
public init(rawValue: String) { self.rawValue = rawValue }
494-
public func hash(into hasher: inout Hasher) { hasher.combine(rawValue) }
495-
public static func ==(_ lhs: ProgressUserInfoKey, _ rhs: ProgressUserInfoKey) -> Bool { return lhs.rawValue == rhs.rawValue }
496-
490+
497491
/// How much time is probably left in the operation, as an NSNumber containing a number of seconds.
498492
///
499493
/// If this value is present, then `Progress` can present a more detailed `localizedAdditionalDescription`.

Foundation/Stream.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ extension Stream {
2828
public init(rawValue: String) {
2929
self.rawValue = rawValue
3030
}
31-
32-
public func hash(into hasher: inout Hasher) {
33-
hasher.combine(rawValue)
34-
}
35-
36-
public static func ==(lhs: Stream.PropertyKey, rhs: Stream.PropertyKey) -> Bool {
37-
return lhs.rawValue == rhs.rawValue
38-
}
3931
}
4032

4133
public enum Status : UInt {
@@ -303,12 +295,6 @@ public struct StreamSocketSecurityLevel : RawRepresentable, Equatable, Hashable
303295
public init(rawValue: String) {
304296
self.rawValue = rawValue
305297
}
306-
public func hash(into hasher: inout Hasher) {
307-
hasher.combine(rawValue)
308-
}
309-
public static func ==(lhs: StreamSocketSecurityLevel, rhs: StreamSocketSecurityLevel) -> Bool {
310-
return lhs.rawValue == rhs.rawValue
311-
}
312298
}
313299
extension StreamSocketSecurityLevel {
314300
public static let none = StreamSocketSecurityLevel(rawValue: "kCFStreamSocketSecurityLevelNone")
@@ -325,12 +311,6 @@ public struct StreamSOCKSProxyConfiguration : RawRepresentable, Equatable, Hasha
325311
public init(rawValue: String) {
326312
self.rawValue = rawValue
327313
}
328-
public func hash(into hasher: inout Hasher) {
329-
hasher.combine(rawValue)
330-
}
331-
public static func ==(lhs: StreamSOCKSProxyConfiguration, rhs: StreamSOCKSProxyConfiguration) -> Bool {
332-
return lhs.rawValue == rhs.rawValue
333-
}
334314
}
335315
extension StreamSOCKSProxyConfiguration {
336316
public static let hostKey = StreamSOCKSProxyConfiguration(rawValue: "NSStreamSOCKSProxyKey")
@@ -347,12 +327,6 @@ public struct StreamSOCKSProxyVersion : RawRepresentable, Equatable, Hashable {
347327
public init(rawValue: String) {
348328
self.rawValue = rawValue
349329
}
350-
public func hash(into hasher: inout Hasher) {
351-
hasher.combine(rawValue)
352-
}
353-
public static func ==(lhs: StreamSOCKSProxyVersion, rhs: StreamSOCKSProxyVersion) -> Bool {
354-
return lhs.rawValue == rhs.rawValue
355-
}
356330
}
357331
extension StreamSOCKSProxyVersion {
358332
public static let version4 = StreamSOCKSProxyVersion(rawValue: "kCFStreamSocketSOCKSVersion4")
@@ -366,12 +340,6 @@ public struct StreamNetworkServiceTypeValue : RawRepresentable, Equatable, Hasha
366340
public init(rawValue: String) {
367341
self.rawValue = rawValue
368342
}
369-
public func hash(into hasher: inout Hasher) {
370-
hasher.combine(rawValue)
371-
}
372-
public static func ==(lhs: StreamNetworkServiceTypeValue, rhs: StreamNetworkServiceTypeValue) -> Bool {
373-
return lhs.rawValue == rhs.rawValue
374-
}
375343
}
376344
extension StreamNetworkServiceTypeValue {
377345
public static let voIP = StreamNetworkServiceTypeValue(rawValue: "kCFStreamNetworkServiceTypeVoIP")

Foundation/StringEncodings.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,7 @@ extension String {
6868
}
6969

7070
extension String.Encoding : Hashable {
71-
public func hash(into hasher: inout Hasher) {
72-
hasher.combine(rawValue)
73-
}
74-
75-
public static func ==(lhs: String.Encoding, rhs: String.Encoding) -> Bool {
76-
return lhs.rawValue == rhs.rawValue
77-
}
71+
// ==, hash(into:) supplied by RawRepresentable
7872
}
7973

8074
extension String.Encoding : CustomStringConvertible {

0 commit comments

Comments
 (0)