Skip to content

Commit 4afd18e

Browse files
authored
Merge pull request #282 from compnerd/277
TSCBasic: repair the Windows build after #277
2 parents 6f2fecd + 27ebddb commit 4afd18e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Sources/TSCBasic/Lock.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,18 @@ public final class FileLock {
178178
throw FileSystemError(.notDirectory, lockFilesDirectory)
179179
}
180180
// use the parent path to generate unique filename in temp
181-
var lockFileName = (resolveSymlinks(fileToLock.parentDirectory).appending(component: fileToLock.basename)).components.joined(separator: "_") + ".lock"
181+
var lockFileName = (resolveSymlinks(fileToLock.parentDirectory)
182+
.appending(component: fileToLock.basename))
183+
.components.joined(separator: "_")
184+
.replacingOccurrences(of: ":", with: "_") + ".lock"
185+
#if os(Windows)
186+
// NTFS has an ARC limit of 255 codepoints
187+
var lockFileUTF16 = lockFileName.utf16.suffix(255)
188+
while String(lockFileUTF16) == nil {
189+
lockFileUTF16 = lockFileUTF16.dropFirst()
190+
}
191+
lockFileName = String(lockFileUTF16) ?? lockFileName
192+
#else
182193
if lockFileName.hasPrefix(AbsolutePath.root.pathString) {
183194
lockFileName = String(lockFileName.dropFirst(AbsolutePath.root.pathString.count))
184195
}
@@ -191,6 +202,7 @@ public final class FileLock {
191202
}
192203
// we will never end up with nil since we have ASCII characters at the end
193204
lockFileName = String(lockFileUTF8) ?? lockFileName
205+
#endif
194206
let lockFilePath = lockFilesDirectory.appending(component: lockFileName)
195207

196208
let lock = FileLock(at: lockFilePath)

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,10 +768,10 @@ class FileSystemTests: XCTestCase {
768768

769769
try _testFileSystemFileLock(fileSystem: localFileSystem, fileA: fileA, fileB: fileB, lockFile: lockFile)
770770

771-
// Test some long and edge case paths. We arrange to split between the C and the Cedilla if NAME_MAX is 255.
772-
let longEdgeCase1 = tempDir.appending(component: String(repeating: "Façade! ", count: Int(NAME_MAX)).decomposedStringWithCanonicalMapping)
771+
// Test some long and edge case paths. We arrange to split between the C and the Cedilla by repeating 255 times.
772+
let longEdgeCase1 = tempDir.appending(component: String(repeating: "Façade! ", count: 255).decomposedStringWithCanonicalMapping)
773773
try localFileSystem.withLock(on: longEdgeCase1, type: .exclusive, {})
774-
let longEdgeCase2 = tempDir.appending(component: String(repeating: "🏁", count: Int(NAME_MAX)).decomposedStringWithCanonicalMapping)
774+
let longEdgeCase2 = tempDir.appending(component: String(repeating: "🏁", count: 255).decomposedStringWithCanonicalMapping)
775775
try localFileSystem.withLock(on: longEdgeCase2, type: .exclusive, {})
776776
}
777777
}

0 commit comments

Comments
 (0)