@@ -12,11 +12,7 @@ import Foundation
12
12
import WinSDK
13
13
#endif
14
14
15
- #if os(Windows)
16
- private typealias PathImpl = UNIXPath
17
- #else
18
15
private typealias PathImpl = UNIXPath
19
- #endif
20
16
21
17
/// Represents an absolute file system path, independently of what (or whether
22
18
/// anything at all) exists at that path in the file system at any given time.
@@ -453,16 +449,12 @@ private struct UNIXPath: Path {
453
449
defer { fsr. deallocate ( ) }
454
450
455
451
let path : String = String ( cString: fsr)
456
- let dir : String = path. withCString ( encodedAs: UTF16 . self) {
452
+ let result : String = path. withCString ( encodedAs: UTF16 . self) {
457
453
let data = UnsafeMutablePointer ( mutating: $0)
458
454
PathCchRemoveFileSpec ( data, path. count)
459
455
return String ( decodingCString: data, as: UTF16 . self)
460
456
}
461
- // Blank path represents for the current directory.
462
- if dir == " " {
463
- return " . "
464
- }
465
- return dir
457
+ return result. isEmpty ? " . " : result
466
458
#else
467
459
// FIXME: This method seems too complicated; it should be simplified,
468
460
// if possible, and certainly optimized (using UTF8View).
@@ -621,12 +613,12 @@ private struct UNIXPath: Path {
621
613
622
614
init ( normalizingRelativePath path: String ) {
623
615
let pathSeparator : Character
624
- #if os(Windows)
616
+ #if os(Windows)
625
617
pathSeparator = " \\ "
626
618
let path = path. replacingOccurrences ( of: " / " , with: " \\ " )
627
- #else
619
+ #else
628
620
pathSeparator = " / "
629
- #endif
621
+ #endif
630
622
precondition ( path. first != pathSeparator)
631
623
632
624
// FIXME: Here we should also keep track of whether anything actually has
@@ -690,7 +682,7 @@ private struct UNIXPath: Path {
690
682
}
691
683
692
684
init ( validatingAbsolutePath path: String ) throws {
693
- #if os(Windows)
685
+ #if os(Windows)
694
686
guard path != " " else {
695
687
throw PathValidationError . invalidAbsolutePath ( path)
696
688
}
@@ -702,7 +694,7 @@ private struct UNIXPath: Path {
702
694
throw PathValidationError . invalidAbsolutePath ( path)
703
695
}
704
696
self . init ( normalizingAbsolutePath: path)
705
- #else
697
+ #else
706
698
switch path. first {
707
699
case " / " :
708
700
self . init ( normalizingAbsolutePath: path)
@@ -711,11 +703,11 @@ private struct UNIXPath: Path {
711
703
default :
712
704
throw PathValidationError . invalidAbsolutePath ( path)
713
705
}
714
- #endif
706
+ #endif
715
707
}
716
708
717
709
init ( validatingRelativePath path: String ) throws {
718
- #if os(Windows)
710
+ #if os(Windows)
719
711
guard path != " " else {
720
712
self . init ( normalizingRelativePath: path)
721
713
return
@@ -728,14 +720,14 @@ private struct UNIXPath: Path {
728
720
throw PathValidationError . invalidRelativePath ( path)
729
721
}
730
722
self . init ( normalizingRelativePath: path)
731
- #else
723
+ #else
732
724
switch path. first {
733
725
case " / " , " ~ " :
734
726
throw PathValidationError . invalidRelativePath ( path)
735
727
default :
736
728
self . init ( normalizingRelativePath: path)
737
729
}
738
- #endif
730
+ #endif
739
731
}
740
732
741
733
func suffix( withDot: Bool ) -> String ? {
0 commit comments