Skip to content

Commit be3f4d0

Browse files
committed
Fix a build failure on Windows, where NAME_MAX doesn't exist.
1 parent bccbd93 commit be3f4d0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Sources/TSCBasic/Lock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public final class FileLock {
182182
if lockFileName.hasPrefix(AbsolutePath.root.pathString) {
183183
lockFileName = String(lockFileName.dropFirst(AbsolutePath.root.pathString.count))
184184
}
185+
#if !os(Windows)
185186
// back off until it occupies at most `NAME_MAX` UTF-8 bytes but without splitting scalars
186187
// (we might split clusters but it's not worth the effort to keep them together as long as we get a valid file name)
187188
var lockFileUTF8 = lockFileName.utf8.suffix(Int(NAME_MAX))
@@ -191,6 +192,7 @@ public final class FileLock {
191192
}
192193
// we will never end up with nil since we have ASCII characters at the end
193194
lockFileName = String(lockFileUTF8) ?? lockFileName
195+
#endif
194196
let lockFilePath = lockFilesDirectory.appending(component: lockFileName)
195197

196198
let lock = FileLock(at: lockFilePath)

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,13 @@ class FileSystemTests: XCTestCase {
767767
let lockFile = tempDir.appending(component: "lockfile")
768768

769769
try _testFileSystemFileLock(fileSystem: localFileSystem, fileA: fileA, fileB: fileB, lockFile: lockFile)
770-
770+
#if !os(Windows)
771771
// Test some long and edge case paths. We arrange to split between the C and the Cedilla if NAME_MAX is 255.
772772
let longEdgeCase1 = tempDir.appending(component: String(repeating: "Façade! ", count: Int(NAME_MAX)).decomposedStringWithCanonicalMapping)
773773
try localFileSystem.withLock(on: longEdgeCase1, type: .exclusive, {})
774774
let longEdgeCase2 = tempDir.appending(component: String(repeating: "🏁", count: Int(NAME_MAX)).decomposedStringWithCanonicalMapping)
775775
try localFileSystem.withLock(on: longEdgeCase2, type: .exclusive, {})
776+
#endif
776777
}
777778
}
778779

0 commit comments

Comments
 (0)