Skip to content

Commit 39704db

Browse files
committed
Minor update
1 parent 55565ba commit 39704db

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

Sources/TSCBasic/Path.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ extension Path {
114114
}
115115

116116
public var suffix: String? {
117-
if let ext = `extension` {
118-
return ".\(ext)"
117+
if let ext = self.extension {
118+
return "." + ext
119119
} else {
120120
return nil
121121
}

Sources/TSCBasic/PathShims.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import TSCLibc
2121
import Foundation
22-
import SystemPackage
2322

2423
/// Returns the "real path" corresponding to `path` by resolving any symbolic links.
2524
public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
@@ -169,18 +168,16 @@ extension AbsolutePath {
169168
/// Returns a path suitable for display to the user (if possible, it is made
170169
/// to be relative to the current working directory).
171170
public func prettyPath(cwd: AbsolutePath? = localFileSystem.currentWorkingDirectory) -> String {
172-
guard let dir = cwd else {
173-
// No current directory, display as is.
171+
guard let dir = cwd,
172+
let rel = try? relative(to: dir) else {
173+
// Cannot create relative path, display as is.
174174
return self.pathString
175175
}
176-
// FIXME: Instead of string prefix comparison we should add a proper API
177-
// to AbsolutePath to determine ancestry.
178-
if self == dir {
179-
return "."
180-
} else if self.pathString.hasPrefix(dir.pathString + "/") {
181-
return try! "./" + self.relative(to: dir).pathString
176+
if let first = rel.components.first,
177+
first != ".." {
178+
return "./" + rel.pathString
182179
} else {
183-
return self.pathString
180+
return rel.pathString
184181
}
185182
}
186183
}

0 commit comments

Comments
 (0)