From 2356d0603f70cad90f76fa57999054bf5c0a9157 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 18 Mar 2021 05:25:56 -0700 Subject: followup #17398: `getTempDir`, `getConfigDir` now do not have trailing DirSep (#17402) * followup #17398: `getTempDir`, `getConfigDir` now do not have trailing DirSep * fix test --- lib/pure/os.nim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/pure/os.nim') diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 00a5f9342..d0b3aef1a 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -917,10 +917,7 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1", ## On non-Windows OSs, this proc conforms to the XDG Base Directory ## spec. Thus, this proc returns the value of the `XDG_CONFIG_HOME` environment ## variable if it is set, otherwise it returns the default configuration - ## directory ("~/.config/"). - ## - ## An OS-dependent trailing slash is always present at the end of the - ## returned string: `\\` on Windows and `/` on all other OSs. + ## directory ("~/.config"). ## ## See also: ## * `getHomeDir proc <#getHomeDir>`_ @@ -928,12 +925,15 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1", ## * `expandTilde proc <#expandTilde,string>`_ ## * `getCurrentDir proc <#getCurrentDir>`_ ## * `setCurrentDir proc <#setCurrentDir,string>`_ + runnableExamples: + from std/strutils import endsWith + # See `getHomeDir` for behavior regarding trailing DirSep. + assert not getConfigDir().endsWith DirSep when defined(windows): result = getEnv("APPDATA") else: result = getEnv("XDG_CONFIG_HOME", getEnv("HOME") / ".config") - result.normalizePathEnd(trailingSep = true) - + result.normalizePathEnd(trailingSep = defined(nimLegacyHomeDir)) when defined(windows): type DWORD = uint32 @@ -975,6 +975,10 @@ proc getTempDir*(): string {.rtl, extern: "nos$1", ## * `expandTilde proc <#expandTilde,string>`_ ## * `getCurrentDir proc <#getCurrentDir>`_ ## * `setCurrentDir proc <#setCurrentDir,string>`_ + runnableExamples: + from std/strutils import endsWith + # See `getHomeDir` for behavior regarding trailing DirSep. + assert not getTempDir().endsWith(DirSep) const tempDirDefault = "/tmp" when defined(tempDir): const tempDir {.strdefine.}: string = tempDirDefault @@ -995,7 +999,7 @@ proc getTempDir*(): string {.rtl, extern: "nos$1", getTempDirImpl(result) if result.len == 0: result = tempDirDefault - normalizePathEnd(result, trailingSep=true) + result.normalizePathEnd(trailingSep = defined(nimLegacyHomeDir)) proc expandTilde*(path: string): string {. tags: [ReadEnvEffect, ReadIOEffect].} = -- cgit 1.4.1-2-gfad0