Skip to content

Commit b214a12

Browse files
authored
Revert "FileLock encounters a runtime error when the path of the locked file is long (#277)"
This reverts commit bccbd93.
1 parent bccbd93 commit b214a12

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

Sources/TSCBasic/Lock.swift

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -178,21 +178,12 @@ 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).appending(component: fileToLock.basename)).components.joined(separator: "_")
182182
if lockFileName.hasPrefix(AbsolutePath.root.pathString) {
183183
lockFileName = String(lockFileName.dropFirst(AbsolutePath.root.pathString.count))
184184
}
185-
// back off until it occupies at most `NAME_MAX` UTF-8 bytes but without splitting scalars
186-
// (we might split clusters but it's not worth the effort to keep them together as long as we get a valid file name)
187-
var lockFileUTF8 = lockFileName.utf8.suffix(Int(NAME_MAX))
188-
while String(lockFileUTF8) == nil {
189-
// in practice this will only be a few iterations
190-
lockFileUTF8 = lockFileUTF8.dropFirst()
191-
}
192-
// we will never end up with nil since we have ASCII characters at the end
193-
lockFileName = String(lockFileUTF8) ?? lockFileName
194-
let lockFilePath = lockFilesDirectory.appending(component: lockFileName)
195-
185+
let lockFilePath = lockFilesDirectory.appending(component: lockFileName + ".lock")
186+
196187
let lock = FileLock(at: lockFilePath)
197188
return try lock.withLock(type: type, body)
198189
}

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -767,12 +767,6 @@ class FileSystemTests: XCTestCase {
767767
let lockFile = tempDir.appending(component: "lockfile")
768768

769769
try _testFileSystemFileLock(fileSystem: localFileSystem, fileA: fileA, fileB: fileB, lockFile: lockFile)
770-
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)
773-
try localFileSystem.withLock(on: longEdgeCase1, type: .exclusive, {})
774-
let longEdgeCase2 = tempDir.appending(component: String(repeating: "🏁", count: Int(NAME_MAX)).decomposedStringWithCanonicalMapping)
775-
try localFileSystem.withLock(on: longEdgeCase2, type: .exclusive, {})
776770
}
777771
}
778772

0 commit comments

Comments
 (0)