Merge branch 'pr_removes_tmp_directory' of https://github.com/gradha/babel into gradha-pr_removes_tmp_directory
Conflicts: src/babel.nim
This commit is contained in:
commit
83c07c254f
1 changed files with 26 additions and 5 deletions
|
|
@ -6,6 +6,9 @@ import httpclient, parseopt, os, strutils, osproc, pegs, tables, parseutils,
|
||||||
|
|
||||||
import babelpkg/packageinfo, babelpkg/version, babelpkg/tools, babelpkg/download
|
import babelpkg/packageinfo, babelpkg/version, babelpkg/tools, babelpkg/download
|
||||||
|
|
||||||
|
when not defined(windows):
|
||||||
|
from posix import getpid
|
||||||
|
|
||||||
type
|
type
|
||||||
TOptions = object
|
TOptions = object
|
||||||
forcePrompts: TForcePrompt
|
forcePrompts: TForcePrompt
|
||||||
|
|
@ -388,17 +391,32 @@ proc installFromDir(dir: string, latest: bool, options: TOptions,
|
||||||
|
|
||||||
echo(pkgInfo.name & " installed successfully.")
|
echo(pkgInfo.name & " installed successfully.")
|
||||||
|
|
||||||
|
proc getBabelTempDir(): 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 babel finishes
|
||||||
|
## its work.
|
||||||
|
result = getTempDir() / "babel_"
|
||||||
|
when defined(windows):
|
||||||
|
proc GetCurrentProcessId(): int32 {.stdcall, dynlib: "kernel32",
|
||||||
|
importc: "GetCurrentProcessId".}
|
||||||
|
result.add($GetCurrentProcessId())
|
||||||
|
else:
|
||||||
|
result.add($getpid())
|
||||||
|
|
||||||
proc downloadPkg(url: string, verRange: PVersionRange,
|
proc downloadPkg(url: string, verRange: PVersionRange,
|
||||||
downMethod: TDownloadMethod): string =
|
downMethod: TDownloadMethod): string =
|
||||||
let downloadDir = (getTempDir() / "babel" / getDownloadDirName(url, verRange))
|
let downloadDir = (getBabelTempDir() / getDownloadDirName(url, verRange))
|
||||||
if not existsDir(getTempDir() / "babel"): createDir(getTempDir() / "babel")
|
createDir(downloadDir.extractFilename)
|
||||||
echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...")
|
echo("Downloading ", url, " into ", downloadDir, " using ", downMethod, "...")
|
||||||
doDownload(url, downloadDir, verRange, downMethod)
|
doDownload(url, downloadDir, verRange, downMethod)
|
||||||
result = downloadDir
|
result = downloadDir
|
||||||
|
|
||||||
proc downloadPkg(pkg: TPackage, verRange: PVersionRange): string =
|
proc downloadPkg(pkg: TPackage, verRange: PVersionRange): string =
|
||||||
let downloadDir = (getTempDir() / "babel" / getDownloadDirName(pkg, verRange))
|
let downloadDir = (getBabelTempDir() / getDownloadDirName(pkg, verRange))
|
||||||
if not existsDir(getTempDir() / "babel"): createDir(getTempDir() / "babel")
|
createDir(downloadDir.extractFilename)
|
||||||
let downMethod = pkg.downloadMethod.getDownloadMethod()
|
let downMethod = pkg.downloadMethod.getDownloadMethod()
|
||||||
echo("Downloading ", pkg.name, " into ", downloadDir, " using ", downMethod, "...")
|
echo("Downloading ", pkg.name, " into ", downloadDir, " using ", downMethod, "...")
|
||||||
doDownload(pkg.url, downloadDir, verRange, downMethod)
|
doDownload(pkg.url, downloadDir, verRange, downMethod)
|
||||||
|
|
@ -432,7 +450,8 @@ proc install(packages: seq[tuple[name: string, verRange: PVersionRange]],
|
||||||
else:
|
else:
|
||||||
# If package is not found give the user a chance to update package.json
|
# If package is not found give the user a chance to update package.json
|
||||||
if doPrompt and
|
if doPrompt and
|
||||||
options.prompt(pv.name & " not found in local packages.json, check internet for updated packages?"):
|
options.prompt(pv.name & " not found in local packages.json, " &
|
||||||
|
"check internet for updated packages?"):
|
||||||
update()
|
update()
|
||||||
install(@[pv], options, false)
|
install(@[pv], options, false)
|
||||||
else:
|
else:
|
||||||
|
|
@ -561,5 +580,7 @@ when isMainModule:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
except EBabel:
|
except EBabel:
|
||||||
quit("FAILURE: " & getCurrentExceptionMsg())
|
quit("FAILURE: " & getCurrentExceptionMsg())
|
||||||
|
finally:
|
||||||
|
removeDir(getBabelTempDir())
|
||||||
else:
|
else:
|
||||||
parseCmdLine().doAction()
|
parseCmdLine().doAction()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue