Skip to content

Commit 54d5d3e

Browse files
committed
restore the ability to do per-file locking
1 parent 161c829 commit 54d5d3e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Sources/TSCBasic/FileSystem.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public class InMemoryFileSystem: FileSystem {
552552
/// reality, the only practical use for InMemoryFileSystem is for unit
553553
/// tests.
554554
private let lock = Lock()
555-
555+
/// Exclusive file system lock vended to clients through `withLock()`.
556556
private var lockFiles = Dictionary<AbsolutePath, WeakReference<DispatchQueue>>()
557557
/// Used to access lockFiles in a thread safe manner.
558558
private let lockFilesLock = Lock()
@@ -906,17 +906,15 @@ public class InMemoryFileSystem: FileSystem {
906906
}
907907

908908
public func withLock<T>(on path: AbsolutePath, type: FileLock.LockType = .exclusive, _ body: () throws -> T) throws -> T {
909-
let fileQueue: DispatchQueue = try lockFilesLock.withLock {
910-
911-
let resolvedPath: AbsolutePath
912-
913-
// FIXME: resolving symlinks is not yet thread safe
909+
let resolvedPath: AbsolutePath = try lock.withLock {
914910
if case let .symlink(destination) = try getNode(path)?.contents {
915-
resolvedPath = AbsolutePath(destination, relativeTo: path.parentDirectory)
911+
return AbsolutePath(destination, relativeTo: path.parentDirectory)
916912
} else {
917-
resolvedPath = path
913+
return path
918914
}
915+
}
919916

917+
let fileQueue: DispatchQueue = lockFilesLock.withLock {
920918
if let queueReference = lockFiles[resolvedPath], let queue = queueReference.reference {
921919
return queue
922920
} else {

0 commit comments

Comments
 (0)