@@ -240,33 +240,6 @@ public struct RelativePath: Hashable, Sendable {
240
240
_impl = impl
241
241
}
242
242
243
- /// Private initializer for constructing a relative path without performing
244
- /// normalization or canonicalization. This will construct a path without
245
- /// an anchor and thus may be invalid.
246
- ///
247
- /*
248
- fileprivate init(unsafeUncheckedPath string: String) {
249
- self.init(PathImpl(string: string))
250
- }*/
251
-
252
- /// Initializes the RelativePath from `str`, which must be a relative path
253
- /// (which means that it must not begin with a path separator or a tilde).
254
- /// An empty input path is allowed, but will be normalized to a single `.`
255
- /// character. The input string will be normalized if needed, as described
256
- /// in the documentation for RelativePath.
257
- /*public init(_ string: String) {
258
- // Normalize the relative string and store it as our Path.
259
- self.init(PathImpl(normalizingRelativePath: string))
260
- }*/
261
-
262
- /*
263
- public init(static path: StaticString) {
264
- let pathString = path.withUTF8Buffer {
265
- String(decoding: $0, as: UTF8.self)
266
- }
267
- try! self.init(validating: pathString)
268
- }*/
269
-
270
243
/// Convenience initializer that verifies that the path is relative.
271
244
public init ( validating path: String ) throws {
272
245
try self . init ( PathImpl ( validatingRelativePath: path) )
@@ -441,12 +414,6 @@ protocol Path: Hashable {
441
414
/// Creates a path from its normalized string representation.
442
415
init ( string: String )
443
416
444
- /// Creates a path from an absolute string representation and normalizes it.
445
- //init(normalizingAbsolutePath: String)
446
-
447
- /// Creates a path from an relative string representation and normalizes it.
448
- //init(normalizingRelativePath: String)
449
-
450
417
/// Creates a path from a string representation, validates that it is a valid absolute path and normalizes it.
451
418
init ( validatingAbsolutePath: String ) throws
452
419
@@ -546,6 +513,17 @@ private struct WindowsPath: Path, Sendable {
546
513
return String ( cString: representation)
547
514
}
548
515
516
+ init ( validatingAbsolutePath path: String ) throws {
517
+ let fsr : UnsafePointer < Int8 > = path. fileSystemRepresentation
518
+ defer { fsr. deallocate ( ) }
519
+
520
+ let realpath = String ( cString: fsr)
521
+ if !Self. isAbsolutePath ( realpath) {
522
+ throw PathValidationError . invalidAbsolutePath ( path)
523
+ }
524
+ self . init ( normalizingAbsolutePath: path)
525
+ }
526
+
549
527
init ( validatingRelativePath path: String ) throws {
550
528
if path. isEmpty || path == " . " {
551
529
self . init ( string: " . " )
@@ -812,7 +790,7 @@ private struct UNIXPath: Path, Sendable {
812
790
813
791
init ( validatingRelativePath path: String ) throws {
814
792
switch path. first {
815
- case " / " : //, "~":
793
+ case " / " :
816
794
throw PathValidationError . invalidRelativePath ( path)
817
795
default :
818
796
self . init ( normalizingRelativePath: path)
0 commit comments