Choose USER-specific tmpdir

re: #80
This commit is contained in:
Christopher Dunn 2019-05-25 16:59:53 -05:00
commit cf7c147121
3 changed files with 17 additions and 3 deletions

View file

@ -15,7 +15,7 @@ from compiler/scriptconfig import setupVM
from compiler/astalgo import strTableGet from compiler/astalgo import strTableGet
import compiler/options as compiler_options import compiler/options as compiler_options
import common, version, options, packageinfo, cli import common, version, options, packageinfo, cli, tools
import os, strutils, strtabs, tables, times, osproc, sets, pegs import os, strutils, strtabs, tables, times, osproc, sets, pegs
when not declared(resetAllModulesHard): when not declared(resetAllModulesHard):
@ -382,7 +382,7 @@ proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
# Ensure that "nimblepkg/nimscriptapi" is in the PATH. # Ensure that "nimblepkg/nimscriptapi" is in the PATH.
block: block:
let t = getTempDir() / "nimblecache" let t = getNimbleUserTempDir() / "nimblecache"
let tmpNimscriptApiPath = t / "nimblepkg" / "nimscriptapi.nim" let tmpNimscriptApiPath = t / "nimblepkg" / "nimscriptapi.nim"
createDir(tmpNimscriptApiPath.splitFile.dir) createDir(tmpNimscriptApiPath.splitFile.dir)
writeFile(tmpNimscriptApiPath, nimscriptApi) writeFile(tmpNimscriptApiPath, nimscriptApi)

View file

@ -155,7 +155,7 @@ proc editJson(p: PackageInfo; url, tags, downloadMethod: string) =
proc publish*(p: PackageInfo, o: Options) = proc publish*(p: PackageInfo, o: Options) =
## Publishes the package p. ## Publishes the package p.
let auth = getGithubAuth(o) let auth = getGithubAuth(o)
var pkgsDir = getTempDir() / "nimble-packages-fork" var pkgsDir = getNimbleUserTempDir() / "nimble-packages-fork"
if not forkExists(auth): if not forkExists(auth):
createFork(auth) createFork(auth)
display("Info:", "Waiting 10s to let Github create a fork", display("Info:", "Waiting 10s to let Github create a fork",

View file

@ -162,3 +162,17 @@ proc getNimbleTempDir*(): string =
result.add($GetCurrentProcessId()) result.add($GetCurrentProcessId())
else: else:
result.add($getpid()) result.add($getpid())
proc getNimbleUserTempDir*(): string =
## Returns a path to a temporary directory.
##
## The returned path will be the same for the duration of the process but
## different for different runs of it. You have to make sure to create it
## first. In release builds the directory will be removed when nimble finishes
## its work.
var tmpdir: string
if existsEnv("TMPDIR") and existsEnv("USER"):
tmpdir = joinPath(getEnv("TMPDIR"), getEnv("USER"))
else:
tmpdir = getTempDir()
return tmpdir