Skip to content

Commit fab6f71

Browse files
committed
fixed build on windows
1 parent 0d48bc6 commit fab6f71

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

Sources/TSCBasic/Lock.swift

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,16 @@ public final class FileLock {
7272
public func lock(type: LockType = .exclusive) throws {
7373
#if os(Windows)
7474
if handle == nil {
75-
let h = lockFile.pathString.withCString(encodedAs: UTF16.self, {
76-
switch mode {
77-
case .exclusive:
78-
CreateFileW(
79-
$0,
80-
UInt32(GENERIC_READ) | UInt32(GENERIC_WRITE),
81-
0,
82-
nil,
83-
DWORD(OPEN_ALWAYS),
84-
DWORD(FILE_ATTRIBUTE_NORMAL),
85-
nil
86-
)
87-
case .shared:
88-
CreateFileW(
89-
$0,
90-
UInt32(GENERIC_READ) | UInt32(GENERIC_WRITE),
91-
DWORD(FILE_SHARE_READ),
92-
nil,
93-
DWORD(OPEN_ALWAYS),
94-
DWORD(FILE_ATTRIBUTE_NORMAL),
95-
nil
96-
)
97-
}
75+
let h: HANDLE = lockFile.pathString.withCString(encodedAs: UTF16.self, {
76+
CreateFileW(
77+
$0,
78+
UInt32(GENERIC_READ) | UInt32(GENERIC_WRITE),
79+
UInt32(FILE_SHARE_READ) | UInt32(FILE_SHARE_WRITE),
80+
nil,
81+
DWORD(OPEN_ALWAYS),
82+
DWORD(FILE_ATTRIBUTE_NORMAL),
83+
nil
84+
)
9885
})
9986
if h == INVALID_HANDLE_VALUE {
10087
throw FileSystemError(errno: Int32(GetLastError()))
@@ -105,7 +92,7 @@ public final class FileLock {
10592
overlapped.Offset = 0
10693
overlapped.OffsetHigh = 0
10794
overlapped.hEvent = nil
108-
switch mode {
95+
switch type {
10996
case .exclusive:
11097
if !LockFileEx(handle, DWORD(LOCKFILE_EXCLUSIVE_LOCK), 0,
11198
DWORD(INT_MAX), DWORD(INT_MAX), &overlapped) {

0 commit comments

Comments
 (0)