Skip to content

Commit

Permalink
Choose USER-specific tmpdir
Browse files Browse the repository at this point in the history
  • Loading branch information
cdunn2001 committed May 26, 2019
1 parent f17eaef commit cf7c147
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/nimblepkg/nimscriptsupport.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/nimblepkg/publish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions src/nimblepkg/tools.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cf7c147

Please sign in to comment.