Skip to content

Commit 8edc44e

Browse files
committed
cleanup
1 parent c12822c commit 8edc44e

File tree

4 files changed

+13
-340
lines changed

4 files changed

+13
-340
lines changed

Sources/TSCBasic/Path.swift

+12-34
Original file line numberDiff line numberDiff line change
@@ -240,33 +240,6 @@ public struct RelativePath: Hashable, Sendable {
240240
_impl = impl
241241
}
242242

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-
270243
/// Convenience initializer that verifies that the path is relative.
271244
public init(validating path: String) throws {
272245
try self.init(PathImpl(validatingRelativePath: path))
@@ -441,12 +414,6 @@ protocol Path: Hashable {
441414
/// Creates a path from its normalized string representation.
442415
init(string: String)
443416

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-
450417
/// Creates a path from a string representation, validates that it is a valid absolute path and normalizes it.
451418
init(validatingAbsolutePath: String) throws
452419

@@ -546,6 +513,17 @@ private struct WindowsPath: Path, Sendable {
546513
return String(cString: representation)
547514
}
548515

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+
549527
init(validatingRelativePath path: String) throws {
550528
if path.isEmpty || path == "." {
551529
self.init(string: ".")
@@ -812,7 +790,7 @@ private struct UNIXPath: Path, Sendable {
812790

813791
init(validatingRelativePath path: String) throws {
814792
switch path.first {
815-
case "/": //, "~":
793+
case "/":
816794
throw PathValidationError.invalidRelativePath(path)
817795
default:
818796
self.init(normalizingRelativePath: path)

Sources/TSCTestSupport/FileSystemExtensions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extension AbsolutePath {
8282
try! self.init(validating: pathString)
8383
}
8484

85-
@available(*, deprecated, message: "use init(static: relativeTo:) instead")
85+
@available(*, deprecated, message: "use init(: relativeTo:) instead")
8686
public init(path: StaticString, relativeTo basePath: AbsolutePath) {
8787
let pathString = path.withUTF8Buffer {
8888
String(decoding: $0, as: UTF8.self)

debug

-1
This file was deleted.

0 commit comments

Comments
 (0)