Fixes more problems with the uninstall feature.
This commit is contained in:
parent
014b897718
commit
35fef81b66
3 changed files with 82 additions and 38 deletions
|
|
@ -325,6 +325,18 @@ proc removeRevDep(options: TOptions, pkg: TPackageInfo) =
|
|||
if thisDep.isNil: continue
|
||||
options.remove(pkg, depTup, thisDep)
|
||||
|
||||
# Clean up empty objects/arrays
|
||||
var newData = newJObject()
|
||||
for key, val in options.babelData["reverseDeps"]:
|
||||
if val.len != 0:
|
||||
var newVal = newJObject()
|
||||
for ver, elem in val:
|
||||
if elem.len != 0:
|
||||
newVal[ver] = elem
|
||||
if newVal.len != 0:
|
||||
newData[key] = newVal
|
||||
options.babelData["reverseDeps"] = newData
|
||||
|
||||
writeFile(options.getBabelDir() / "babeldata.json", pretty(options.babelData))
|
||||
|
||||
proc install(packages: seq[tuple[name: string, verRange: PVersionRange]],
|
||||
|
|
@ -641,33 +653,36 @@ proc uninstall(options: TOptions) =
|
|||
# Do some verification.
|
||||
for pkgTup in options.action.packages:
|
||||
echo("Looking for ", pkgTup.name, " (", $pkgTup.ver, ")...")
|
||||
let pkgList = getInstalledPkgs(options.getPkgsDir())
|
||||
var pkg: TPackageInfo
|
||||
if not findPkg(pkglist, pkgTup, pkg):
|
||||
let installedPkgs = getInstalledPkgs(options.getPkgsDir())
|
||||
var pkgList = findAllPkgs(installedPkgs, pkgTup)
|
||||
if pkgList.len == 0:
|
||||
raise newException(EBabel, "Package not found")
|
||||
|
||||
echo("Checking reverse dependencies...")
|
||||
# Check whether any packages depend on the one the user is trying to uninstall
|
||||
let thisDep = options.babelData["reverseDeps"][pkgTup.name]
|
||||
if not thisDep.isNil:
|
||||
for ver, val in thisDep.pairs:
|
||||
if ver.newVersion in pkgTup.ver and val.len != 0:
|
||||
assert val.kind == JArray
|
||||
var reason = ""
|
||||
if val.len == 1:
|
||||
reason = val[0]["name"].str & " (" & val[0]["version"].str &
|
||||
") depends on it"
|
||||
else:
|
||||
for i in 0 .. <val.len:
|
||||
reason.add val[i]["name"].str & " (" & val[i]["version"].str & ")"
|
||||
if i != <val.len:
|
||||
reason.add ", "
|
||||
reason.add " depend on it"
|
||||
var errors: seq[string] = @[]
|
||||
for pkg in pkgList:
|
||||
# Check whether any packages depend on the ones the user is trying to
|
||||
# uninstall.
|
||||
let thisPkgsDep = options.babelData["reverseDeps"]{pkg.name}{pkg.version}
|
||||
if not thisPkgsDep.isNil:
|
||||
var reason = ""
|
||||
if thisPkgsDep.len == 1:
|
||||
reason = thisPkgsDep[0]["name"].str &
|
||||
" (" & thisPkgsDep[0]["version"].str & ") depends on it"
|
||||
else:
|
||||
for i in 0 .. <thisPkgsDep.len:
|
||||
reason.add thisPkgsDep[i]["name"].str &
|
||||
" (" & thisPkgsDep[i]["version"].str & ")"
|
||||
if i != <thisPkgsDep.len:
|
||||
reason.add ", "
|
||||
reason.add " depend on it"
|
||||
errors.add("Cannot uninstall " & pkgTup.name & " (" & pkg.version &
|
||||
")" & " because " & reason)
|
||||
else:
|
||||
pkgsToDelete.add pkg
|
||||
|
||||
raise newException(EBabel, "Cannot uninstall " & pkgTup.name &
|
||||
" because " & reason)
|
||||
|
||||
pkgsToDelete.add pkg
|
||||
if pkgsToDelete.len == 0:
|
||||
raise newException(EBabel, "\n " & errors.join("\n "))
|
||||
|
||||
var pkgNames = ""
|
||||
for i in 0 .. <pkgsToDelete.len:
|
||||
|
|
|
|||
|
|
@ -293,6 +293,17 @@ proc findPkg*(pkglist: seq[tuple[pkginfo: TPackageInfo, meta: TMetaData]],
|
|||
r = pkg.pkginfo
|
||||
result = true
|
||||
|
||||
proc findAllPkgs*(pkglist: seq[tuple[pkginfo: TPackageInfo, meta: TMetaData]],
|
||||
dep: TPkgTuple): seq[TPackageInfo] =
|
||||
## Searches ``pkglist`` for packages of which version is within the range
|
||||
## of ``dep.ver``. This is similar to ``findPkg`` but returns multiple
|
||||
## packages if multiple are found.
|
||||
result = @[]
|
||||
for pkg in pkglist:
|
||||
if pkg.pkginfo.name != dep.name and pkg.meta.url != dep.name: continue
|
||||
if withinRange(newVersion(pkg.pkginfo.version), dep.ver):
|
||||
result.add pkg.pkginfo
|
||||
|
||||
proc getRealDir*(pkgInfo: TPackageInfo): string =
|
||||
## Returns the ``pkgInfo.srcDir`` or the .mypath directory if package does
|
||||
## not specify the src dir.
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
import osproc, unittest, strutils, os
|
||||
import osproc, unittest, strutils, os, sequtils, future
|
||||
|
||||
const path = "../src/babel"
|
||||
|
||||
discard execCmdEx("nimrod c " & path)
|
||||
test "can compile babel":
|
||||
check execCmdEx("nimrod c " & path).exitCode == QuitSuccess
|
||||
|
||||
template cd*(dir: string, body: stmt) =
|
||||
## Sets the current dir to ``dir``, executes ``body`` and restores the
|
||||
|
|
@ -14,10 +15,13 @@ template cd*(dir: string, body: stmt) =
|
|||
body
|
||||
setCurrentDir(lastDir)
|
||||
|
||||
proc processOutput(output: string): seq[string] =
|
||||
output.strip.splitLines().filter((x: string) => (x.len > 0))
|
||||
|
||||
test "can install packagebin2":
|
||||
let (outp, exitCode) = execCmdEx(path &
|
||||
" install -y https://github.com/babel-test/packagebin2.git")
|
||||
check exitCode == QuitSuccess
|
||||
check execCmdEx(path &
|
||||
" install -y https://github.com/babel-test/packagebin2.git").exitCode ==
|
||||
QuitSuccess
|
||||
|
||||
test "can reject same version dependencies":
|
||||
let (outp, exitCode) = execCmdEx(path &
|
||||
|
|
@ -30,8 +34,7 @@ test "can reject same version dependencies":
|
|||
"dependency on PackageA 0.2.0 and PackageA 0.5.0 [EBabel]"
|
||||
|
||||
test "can update":
|
||||
let (outp, exitCode) = execCmdEx(path & " update")
|
||||
check exitCode == QuitSuccess
|
||||
check execCmdEx(path & " update").exitCode == QuitSuccess
|
||||
|
||||
test "issue #27":
|
||||
# Install b
|
||||
|
|
@ -46,12 +49,27 @@ test "issue #27":
|
|||
check execCmdEx("../" & path & " install -y").exitCode == QuitSuccess
|
||||
|
||||
test "can uninstall":
|
||||
let (outp, exitCode) = execCmdEx(path & " uninstall -y issue27b")
|
||||
let ls = outp.strip.splitLines()
|
||||
check exitCode != QuitSuccess
|
||||
check ls[ls.len-1] == "Error: unhandled exception: Cannot uninstall issue27b" &
|
||||
" because issue27a (0.1.0) depends on it [EBabel]"
|
||||
block:
|
||||
let (outp, exitCode) = execCmdEx(path & " uninstall -y issue27b")
|
||||
let ls = outp.processOutput()
|
||||
check exitCode != QuitSuccess
|
||||
check ls[ls.len-1] == " Cannot uninstall issue27b (0.1.0) because " &
|
||||
"issue27a (0.1.0) depends on it [EBabel]"
|
||||
|
||||
check execCmdEx(path & " uninstall -y issue27").exitCode == QuitSuccess
|
||||
check execCmdEx(path & " uninstall -y issue27a").exitCode == QuitSuccess
|
||||
check execCmdEx(path & " uninstall -y issue27b").exitCode == QuitSuccess
|
||||
check execCmdEx(path & " uninstall -y issue27").exitCode == QuitSuccess
|
||||
check execCmdEx(path & " uninstall -y issue27a").exitCode == QuitSuccess
|
||||
check execCmdEx(path & " uninstall -y issue27b").exitCode == QuitSuccess
|
||||
|
||||
# Remove Package*
|
||||
let (outp, exitCode) = execCmdEx(path & " uninstall -y PackageA")
|
||||
check exitCode != QuitSuccess
|
||||
let ls = outp.processOutput()
|
||||
check ls[ls.len-3].startsWith(" Cannot uninstall PackageA ")
|
||||
check ls[ls.len-2].startsWith(" Cannot uninstall PackageA ")
|
||||
check ls[ls.len-1].startsWith(" Cannot uninstall PackageA ")
|
||||
check execCmdEx(path & " uninstall -y PackageBin2").exitCode == QuitSuccess
|
||||
|
||||
# Case insensitive
|
||||
check execCmdEx(path & " uninstall -y packagea").exitCode == QuitSuccess
|
||||
|
||||
check execCmdEx(path & " uninstall -y PackageA").exitCode != QuitSuccess
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue