Temp files are no longer removed when --debug is present.

This commit is contained in:
Dominik Picheta 2019-09-21 22:54:08 +01:00
commit 36c4a39674
3 changed files with 18 additions and 6 deletions

View file

@ -1040,7 +1040,7 @@ proc test(options: Options) =
display("Error:", error, Error, HighPriority)
proc check(options: Options) =
## Validates a package a in the current working directory.
## Validates a package in the current working directory.
let nimbleFile = findNimbleFile(getCurrentDir(), true)
var error: ValidationError
var pkgInfo: PackageInfo
@ -1134,8 +1134,10 @@ when isMainModule:
var error = ""
var hint = ""
var opt: Options
try:
parseCmdLine().doAction()
opt = parseCmdLine()
opt.doAction()
except NimbleError:
let currentExc = (ref NimbleError)(getCurrentException())
(error, hint) = getOutputInfo(currentExc)
@ -1143,7 +1145,9 @@ when isMainModule:
discard
finally:
try:
removeDir(getNimbleTempDir())
let folder = getNimbleTempDir()
if opt.shouldRemoveTmp(folder):
removeDir(folder)
except OSError:
let msg = "Couldn't remove Nimble's temp dir"
display("Warning:", msg, Warning, MediumPriority)

View file

@ -36,8 +36,8 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options):
defer:
# Only if copied in this invocation, allows recursive calls of nimble
if not isScriptResultCopied:
nimsFileCopied.removeFile()
if not isScriptResultCopied and options.shouldRemoveTmp(nimsFileCopied):
nimsFileCopied.removeFile()
var
cmd = ("nim e --hints:off --verbosity:0 -p:" & (getTempDir() / "nimblecache").quoteShell &
@ -56,7 +56,8 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options):
result.exitCode = execCmd(cmd)
if outFile.fileExists():
result.output = outFile.readFile()
discard outFile.tryRemoveFile()
if options.shouldRemoveTmp(outFile):
discard outFile.tryRemoveFile()
proc getNimsFile(scriptName: string, options: Options): string =
let

View file

@ -425,3 +425,10 @@ proc briefClone*(options: Options): Options =
newOptions.forcePrompts = options.forcePrompts
newOptions.pkgInfoCache = options.pkgInfoCache
return newOptions
proc shouldRemoveTmp*(options: Options, file: string): bool =
result = true
if options.verbosity <= DebugPriority:
let msg = "Not removing temporary path because of debug verbosity: " & file
display("Warning:", msg, Warning, MediumPriority)
return false