make ospaths compile for Android again, simplify its implementation, added a disclaimer

This commit is contained in:
Andreas Rumpf
2017-08-30 11:08:49 +02:00
parent eb8371012c
commit 80fab1d861

View File

@@ -528,28 +528,20 @@ when declared(getEnv) or defined(nimscript):
elif getEnv("XDG_CONFIG_DIR"): return string(getEnv("XDG_CONFIG_DIR")) & "/"
else: return string(getEnv("HOME")) & "/.config/"
when defined(android):
when declared(os):
{.pragma: getTempDirEffects, tags: [ReadEnvEffect, ReadIOEffect, WriteDirEffect].}
else:
{.pragma: getTempDirEffects, tags: [ReadEnvEffect, ReadIOEffect].}
elif defined(windows):
{.pragma: getTempDirEffects, tags: [ReadEnvEffect, ReadIOEffect].}
else:
{.pragma: getTempDirEffects, tags: [ReadIOEffect].}
proc getTempDir*(): string {.rtl, extern: "nos$1",
getTempDirEffects.} =
tags: [ReadEnvEffect, ReadIOEffect].} =
## Returns the temporary directory of the current user for applications to
## save temporary files in.
##
## **Please do not use this**: On Android, it currently
## returns ``getHomeDir()``, and on other Unix based systems it can cause
## security problems too. That said, you can override this implementation
## by adding ``-d:tempDir=mytempname`` to your compiler invokation.
when defined(tempDir):
const tempDir {.strdefine.}: string = nil
return tempDir
elif defined(windows): return string(getEnv("TEMP")) & "\\"
elif defined(android):
let tempDir = getHomeDir() / "nimtempfs"
createDir(tempDir)
return tempDir
elif defined(android): return getHomeDir()
else: return "/tmp/"
proc expandTilde*(path: string): string {.