diff --git a/Sources/System/FilePath/FilePathComponents.swift b/Sources/System/FilePath/FilePathComponents.swift index 22fbe10..c7aed66 100644 --- a/Sources/System/FilePath/FilePathComponents.swift +++ b/Sources/System/FilePath/FilePathComponents.swift @@ -94,9 +94,6 @@ extension FilePath.Component { if _path._isParentDirectory(_range) { return .parentDirectory } return .regular } - - /// Whether this component is either special directory `.` or `..`. - public var isSpecialDirectory: Bool { _path._isSpecialDirectory(_range) } } extension FilePath.Root { @@ -207,7 +204,7 @@ extension FilePath: _PlatformStringable { extension FilePath.Component { // The index of the `.` denoting an extension internal func _extensionIndex() -> SystemString.Index? { - guard !isSpecialDirectory, + guard kind == .regular, let idx = _slice.lastIndex(of: .dot), idx != _slice.startIndex else { return nil } diff --git a/Sources/System/FilePath/FilePathSyntax.swift b/Sources/System/FilePath/FilePathSyntax.swift index 070249f..daae8c0 100644 --- a/Sources/System/FilePath/FilePathSyntax.swift +++ b/Sources/System/FilePath/FilePathSyntax.swift @@ -325,7 +325,7 @@ extension FilePath { get { lastComponent?.extension } set { defer { _invariantCheck() } - guard let base = lastComponent, !base.isSpecialDirectory else { return } + guard let base = lastComponent, base.kind == .regular else { return } let suffix: SystemString if let ext = newValue { @@ -373,7 +373,7 @@ extension FilePath { // `\..\foo\bar` should not. components.drop( while: { root == nil && $0.kind == .parentDirectory } - ).allSatisfy { !$0.isSpecialDirectory } + ).allSatisfy { $0.kind == .regular } } /// Collapse `.` and `..` components lexically (i.e. without following diff --git a/Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift b/Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift index 146b720..4aed900 100644 --- a/Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift +++ b/Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift @@ -916,14 +916,12 @@ final class FilePathSyntaxTest: XCTestCase { path.append(".") expect("/.") XCTAssert(path.components.last!.kind == .currentDirectory) - XCTAssert(path.components.last!.isSpecialDirectory) path.lexicallyNormalize() expect("/") path.append("..") expect("/..") XCTAssert(path.components.last!.kind == .parentDirectory) - XCTAssert(path.components.last!.isSpecialDirectory) path.lexicallyNormalize() expect("/")