Skip to content

Commit

Permalink
Handle empty path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Feb 23, 2021
1 parent 2954e55 commit c13a770
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Sources/TSCBasic/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,15 @@ private struct UNIXPath: Path {

var dirname: String {
#if os(Windows)
guard string != "" else {
return "."
}
let fsr: UnsafePointer<Int8> = string.fileSystemRepresentation
defer { fsr.deallocate() }

let path: String = String(cString: fsr)
return path.withCString(encodedAs: UTF16.self) {
let data = UnsafeMutablePointer(mutating: $0)
let data = UnsafeMutaßlePointer(mutating: $0)
PathCchRemoveFileSpec(data, path.count)
return String(decodingCString: data, as: UTF16.self)
}
Expand Down Expand Up @@ -685,6 +688,9 @@ private struct UNIXPath: Path {

init(validatingAbsolutePath path: String) throws {
#if os(Windows)
guard path != "" else {
throw PathValidationError.invalidAbsolutePath(path)
}
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
defer { fsr.deallocate() }

Expand All @@ -707,6 +713,9 @@ private struct UNIXPath: Path {

init(validatingRelativePath path: String) throws {
#if os(Windows)
guard path != "" else {
self.init(normalizingRelativePath: path)
}
let fsr: UnsafePointer<Int8> = path.fileSystemRepresentation
defer { fsr.deallocate() }

Expand Down

0 comments on commit c13a770

Please sign in to comment.