I noticed that the output of getHomeDir has a trailing forward slash while getCurrentDir does not. This produces the scenario where if your pwd is your home directory, this code fails.
doAssert(getHomeDir() == getCurrentDir())
My question is, is the discrepancy in formatting intended?
IMO it's a bug that should be fixed (with the usual -d:nimLegacyHomeDir), upvote https://github.com/nim-lang/Nim/issues/17393
PR welcome to see what would break.
getHomeDir() == getCurrentDir()
note, paths should be compared semantically (with os.cmpPaths) but that's a separate issue.
paths should be compared semantically (with os.cmpPaths) but that's a separate issue.
Depends on your point of view. At least with the current inconsistency you're forced to write the code properly and use os.cmpPaths. After we patched it bad code would start to "work".
Worth pointing out that Nim's own documentation compares dirs in this way.
import asyncdispatch, asyncftpclient
proc main() {.async.} =
var ftp = newAsyncFtpClient("example.com", user = "test", pass = "test")
await ftp.connect()
let currentDir = await ftp.pwd()
assert currentDir == "/home/user/"
await ftp.store("file.txt", "file.txt")
echo("File finished uploading")
waitFor(main())