Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/Foundation/FileManager+Win32.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ extension FileManager {
// BACKUP_SEMANTICS are (confusingly) required in order to receive a
// handle to a directory
CreateFileW($0, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nil)
DWORD(FILE_SHARE_READ) | DWORD(FILE_SHARE_WRITE) | DWORD(FILE_SHARE_DELETE),
nil, DWORD(OPEN_EXISTING), DWORD(FILE_FLAG_BACKUP_SEMANTICS), nil)
}
if hFile == INVALID_HANDLE_VALUE {
return try FileManager.default._fileSystemRepresentation(withPath: path) {
Expand Down Expand Up @@ -228,8 +228,8 @@ extension FileManager {

var statInfo = stat()
let handle =
CreateFileW(_fsRep, 0, FILE_SHARE_READ, nil, OPEN_EXISTING,
FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
CreateFileW(_fsRep, 0, DWORD(FILE_SHARE_READ), nil, DWORD(OPEN_EXISTING),
FILE_FLAG_OPEN_REPARSE_POINT | DWORD(FILE_FLAG_BACKUP_SEMANTICS),
nil)
if handle == INVALID_HANDLE_VALUE {
throw _NSErrorWithWindowsError(GetLastError(), reading: false, paths: [path])
Expand Down Expand Up @@ -292,7 +292,7 @@ extension FileManager {
FILETIME(from: time_t((modificationTime ?? stat.lastModificationDate).timeIntervalSince1970))

let hFile: HANDLE =
CreateFileW(fsr, GENERIC_WRITE, FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0,
CreateFileW(fsr, GENERIC_WRITE, DWORD(FILE_SHARE_WRITE), nil, DWORD(OPEN_EXISTING), 0,
nil)
if hFile == INVALID_HANDLE_VALUE {
throw _NSErrorWithWindowsError(GetLastError(), reading: true, paths: [path])
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/NSPathUtilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ internal func _NSCreateTemporaryFile(_ filePath: String) throws -> (Int32, Strin
}
let pathResult = FileManager.default.string(withFileSystemRepresentation: String(decoding: buf, as: UTF16.self), length: wcslen(buf))
guard let h = CreateFileW(buf, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nil),
DWORD(FILE_SHARE_READ) | DWORD(FILE_SHARE_WRITE) | DWORD(FILE_SHARE_DELETE),
nil, DWORD(OPEN_EXISTING), DWORD(FILE_ATTRIBUTE_NORMAL), nil),
h != INVALID_HANDLE_VALUE else {
throw _NSErrorWithWindowsError(GetLastError(), reading: false)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Foundation/NSURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,8 @@ extension NSURL {
#if os(Windows)
let hFile: HANDLE = absolutePath.withCString(encodedAs: UTF16.self) {
CreateFileW($0, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nil)
DWORD(FILE_SHARE_READ) | DWORD(FILE_SHARE_WRITE) | DWORD(FILE_SHARE_DELETE),
nil, DWORD(OPEN_EXISTING), DWORD(FILE_FLAG_BACKUP_SEMANTICS), nil)
}
guard hFile == INVALID_HANDLE_VALUE else {
defer { CloseHandle(hFile) }
Expand Down
24 changes: 0 additions & 24 deletions Sources/Foundation/WinSDK+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ internal var FILE_ATTRIBUTE_DIRECTORY: DWORD {
DWORD(WinSDK.FILE_ATTRIBUTE_DIRECTORY)
}

internal var FILE_ATTRIBUTE_NORMAL: DWORD {
DWORD(WinSDK.FILE_ATTRIBUTE_NORMAL)
}

internal var FILE_ATTRIBUTE_HIDDEN: DWORD {
DWORD(WinSDK.FILE_ATTRIBUTE_HIDDEN)
}
Expand All @@ -33,26 +29,10 @@ internal var FILE_ATTRIBUTE_REPARSE_POINT: DWORD {
DWORD(WinSDK.FILE_ATTRIBUTE_REPARSE_POINT)
}

internal var FILE_FLAG_BACKUP_SEMANTICS: DWORD {
DWORD(WinSDK.FILE_FLAG_BACKUP_SEMANTICS)
}

internal var FILE_FLAG_OPEN_REPARSE_POINT: DWORD {
DWORD(WinSDK.FILE_FLAG_OPEN_REPARSE_POINT)
}

internal var FILE_SHARE_DELETE: DWORD {
DWORD(WinSDK.FILE_SHARE_DELETE)
}

internal var FILE_SHARE_READ: DWORD {
DWORD(WinSDK.FILE_SHARE_READ)
}

internal var FILE_SHARE_WRITE: DWORD {
DWORD(WinSDK.FILE_SHARE_WRITE)
}

internal var GENERIC_WRITE: DWORD {
DWORD(WinSDK.GENERIC_WRITE)
}
Expand All @@ -68,8 +48,4 @@ internal var MOVEFILE_REPLACE_EXISTING: DWORD {
internal var MOVEFILE_WRITE_THROUGH: DWORD {
DWORD(WinSDK.MOVEFILE_WRITE_THROUGH)
}

internal var OPEN_EXISTING: DWORD {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this one was at least required:

C:\Users\swift-ci\jenkins\workspace\swift-corelibs-foundation-PR-windows\swift-corelibs-foundation\Sources\Foundation\FileManager+Win32.swift:187:28: error: cannot convert value of type 'Int32' to expected argument type 'DWORD' (aka 'UInt32')

185 |           CreateFileW($0, 0,

186 |                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,

187 |                       nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nil)

    |                            `- error: cannot convert value of type 'Int32' to expected argument type 'DWORD' (aka 'UInt32')

188 |         }

189 |         if hFile == INVALID_HANDLE_VALUE {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that I need to just do the typecasts here in the repo. There is a compiler issue that the removal fixes :(.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, do you have a link to the compiler issue that this removal is fixing? And is there a future in which this declaration is imported as a DWORD automatically or is it intentionally imported as a different type than how its used here?

DWORD(WinSDK.OPEN_EXISTING)
}
#endif
6 changes: 3 additions & 3 deletions Tests/Foundation/TestFileHandle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ class TestFileHandle : XCTestCase {
// NOTE(compnerd) we need the FILE_FLAG_BACKUP_SEMANTICS so that we
// can create the handle to the directory.
CreateFileW($0, GENERIC_READ,
FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, nil)
DWORD(FILE_SHARE_DELETE) | DWORD(FILE_SHARE_READ) | DWORD(FILE_SHARE_WRITE),
nil, DWORD(OPEN_EXISTING),
DWORD(FILE_ATTRIBUTE_NORMAL) | DWORD(FILE_FLAG_BACKUP_SEMANTICS), nil)
}
if hDirectory == INVALID_HANDLE_VALUE {
fatalError("unable to create handle to current directory")
Expand Down