import Foundation
let file = URL(fileURLWithPath: "main.swift")
let dir = file.deletingLastPathComponent()
print(dir.relativePath) // =>
print(dir.appendingPathComponent("main.swift").path) // => /main.swift
Since main.swift represents a relative path from the current directory, removing the last component should result in . to indicate the current directory. However, it incorrectly results in an empty path ``.
When combined with the bug #921, this behavior causes the path to change unexpectedly when re-adding the removed component, resulting in a different path from the original file.
On macOS, the result is . as expected, so re-adding the removed component restores the path to the original file.
As described in the title, the following occurs:
Since
main.swift
represents a relative path from the current directory, removing the last component should result in.
to indicate the current directory. However, it incorrectly results in an empty path ``.When combined with the bug #921, this behavior causes the path to change unexpectedly when re-adding the removed component, resulting in a different path from the original file.
On macOS, the result is
.
as expected, so re-adding the removed component restores the path to the original file.