From 82d7f53bdc2245ec89b1eb4ae495a05006e438d9 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Tue, 1 Mar 2022 23:17:30 +0800 Subject: [PATCH] Complete `AbsolutePath.relative(to:)` --- Sources/TSCBasic/Path.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/TSCBasic/Path.swift b/Sources/TSCBasic/Path.swift index 5d279008..ec7180d1 100644 --- a/Sources/TSCBasic/Path.swift +++ b/Sources/TSCBasic/Path.swift @@ -396,9 +396,12 @@ extension AbsolutePath { var relFilePath = FilePath() var filepath = filepath #if os(Windows) - /// TODO: DOS relative path may change the root. - if root != base.root { - throw PathValidationError.differentRoot(pathString, base.pathString) + if self.root != base.root { + guard self.root?.count == 3, + self.root!.hasSuffix(":\\") else { + throw PathValidationError.differentRoot(pathString, base.pathString) + } + relFilePath.root = .init(String(self.root!.dropLast())) } #endif filepath.root = base.filepath.root