From cf7c1471217323893059f750da5ac82b096addda Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 25 May 2019 16:59:53 -0500 Subject: [PATCH] Choose USER-specific tmpdir re: #80 --- src/nimblepkg/nimscriptsupport.nim | 4 ++-- src/nimblepkg/publish.nim | 2 +- src/nimblepkg/tools.nim | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/nimblepkg/nimscriptsupport.nim b/src/nimblepkg/nimscriptsupport.nim index 2806251..4c8747b 100644 --- a/src/nimblepkg/nimscriptsupport.nim +++ b/src/nimblepkg/nimscriptsupport.nim @@ -15,7 +15,7 @@ from compiler/scriptconfig import setupVM from compiler/astalgo import strTableGet 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 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. block: - let t = getTempDir() / "nimblecache" + let t = getNimbleUserTempDir() / "nimblecache" let tmpNimscriptApiPath = t / "nimblepkg" / "nimscriptapi.nim" createDir(tmpNimscriptApiPath.splitFile.dir) writeFile(tmpNimscriptApiPath, nimscriptApi) diff --git a/src/nimblepkg/publish.nim b/src/nimblepkg/publish.nim index 2d73478..333bbbd 100644 --- a/src/nimblepkg/publish.nim +++ b/src/nimblepkg/publish.nim @@ -155,7 +155,7 @@ proc editJson(p: PackageInfo; url, tags, downloadMethod: string) = proc publish*(p: PackageInfo, o: Options) = ## Publishes the package p. let auth = getGithubAuth(o) - var pkgsDir = getTempDir() / "nimble-packages-fork" + var pkgsDir = getNimbleUserTempDir() / "nimble-packages-fork" if not forkExists(auth): createFork(auth) display("Info:", "Waiting 10s to let Github create a fork", diff --git a/src/nimblepkg/tools.nim b/src/nimblepkg/tools.nim index 8dc71e2..2073154 100644 --- a/src/nimblepkg/tools.nim +++ b/src/nimblepkg/tools.nim @@ -162,3 +162,17 @@ proc getNimbleTempDir*(): string = result.add($GetCurrentProcessId()) else: 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