@@ -454,7 +454,7 @@ private struct UNIXPath: Path {
454
454
455
455
let path : String = String ( cString: fsr)
456
456
let dir : String = path. withCString ( encodedAs: UTF16 . self) {
457
- let data = UnsafeMutaßlePointer ( mutating: $0)
457
+ let data = UnsafeMutablePointer ( mutating: $0)
458
458
PathCchRemoveFileSpec ( data, path. count)
459
459
return String ( decodingCString: data, as: UTF16 . self)
460
460
}
@@ -549,11 +549,14 @@ private struct UNIXPath: Path {
549
549
550
550
init ( normalizingAbsolutePath path: String ) {
551
551
#if os(Windows)
552
- var buffer : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
552
+ var result : PWSTR ?
553
+ defer { LocalFree ( result) }
554
+
553
555
_ = path. withCString ( encodedAs: UTF16 . self) {
554
- PathCanonicalizeW ( & buffer , $0 )
556
+ PathAllocCanonicalize ( $0 , ULONG ( PATHCCH_ALLOW_LONG_PATHS . rawValue ) , & result )
555
557
}
556
- self . init ( string: String ( decodingCString: buffer, as: UTF16 . self) )
558
+
559
+ self . init ( string: String ( decodingCString: result!, as: UTF16 . self) )
557
560
#else
558
561
precondition ( path. first == " / " , " Failure normalizing \( path) , absolute paths should start with '/' " )
559
562
@@ -619,11 +622,18 @@ private struct UNIXPath: Path {
619
622
620
623
init ( normalizingRelativePath path: String ) {
621
624
#if os(Windows)
622
- var buffer : [ WCHAR ] = Array < WCHAR > ( repeating: 0 , count: Int ( MAX_PATH + 1 ) )
625
+ var result : PWSTR ?
626
+ defer { LocalFree ( result) }
627
+
623
628
_ = path. replacingOccurrences ( of: " / " , with: " \\ " ) . withCString ( encodedAs: UTF16 . self) {
624
- PathCanonicalizeW ( & buffer, $0)
629
+ PathAllocCanonicalize ( $0, ULONG ( PATHCCH_ALLOW_LONG_PATHS . rawValue) , & result)
630
+ }
631
+
632
+ var canonicalized : String = String ( decodingCString: result!, as: UTF16 . self)
633
+ if canonicalized == " " || canonicalized == " \\ " {
634
+ canonicalized = " . "
625
635
}
626
- self . init ( string: String ( decodingCString : buffer , as : UTF16 . self ) )
636
+ self . init ( string: canonicalized )
627
637
#else
628
638
precondition ( path. first != " / " )
629
639
0 commit comments