Skip to content

Rename variables at Lock.swift #2093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2019
Merged
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
30 changes: 15 additions & 15 deletions Sources/Basic/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ enum ProcessLockError: Swift.Error {
public final class FileLock {
/// File descriptor to the lock file.
#if os(Windows)
private var h: HANDLE?
private var handle: HANDLE?
#else
private var fd: CInt?
private var fileDescriptor: CInt?
#endif

/// Path to the lock file.
Expand All @@ -58,7 +58,7 @@ public final class FileLock {
/// Note: This method can throw if underlying POSIX methods fail.
public func lock() throws {
#if os(Windows)
if h == nil {
if handle == nil {
let h = lockFile.pathString.withCString(encodedAs: UTF16.self, {
CreateFileW(
$0,
Expand All @@ -69,11 +69,11 @@ public final class FileLock {
DWORD(FILE_ATTRIBUTE_NORMAL),
nil
)
})
if h == INVALID_HANDLE_VALUE {
throw FileSystemError(errno: Int32(GetLastError()))
}
self.h = h
})
if h == INVALID_HANDLE_VALUE {
throw FileSystemError(errno: Int32(GetLastError()))
}
self.handle = h
}
var overlapped = OVERLAPPED()
overlapped.Offset = 0
Expand All @@ -84,16 +84,16 @@ public final class FileLock {
}
#else
// Open the lock file.
if fd == nil {
if fileDescriptor == nil {
let fd = SPMLibc.open(lockFile.pathString, O_WRONLY | O_CREAT | O_CLOEXEC, 0o666)
if fd == -1 {
throw FileSystemError(errno: errno)
}
self.fd = fd
self.fileDescriptor = fd
}
// Aquire lock on the file.
while true {
if flock(fd!, LOCK_EX) == 0 {
if flock(fileDescriptor!, LOCK_EX) == 0 {
break
}
// Retry if interrupted.
Expand All @@ -112,17 +112,17 @@ public final class FileLock {
overlapped.hEvent = nil
UnlockFileEx(h, 0, DWORD(INT_MAX), DWORD(INT_MAX), &overlapped)
#else
guard let fd = fd else { return }
guard let fd = fileDescriptor else { return }
flock(fd, LOCK_UN)
#endif
}

deinit {
#if os(Windows)
guard let h = h else { return }
CloseHandle(h)
guard let handle = handle else { return }
CloseHandle(handle)
#else
guard let fd = fd else { return }
guard let fd = fileDescriptor else { return }
close(fd)
#endif
}
Expand Down