Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fix package download not using refreshed package list

* Added test

* Use exitCode to remove warning

* Use clearer identifier names (`ignorePackageCache` instead of `clean`)
  • Loading branch information
ire4ever1190 authored Dec 15, 2021
1 parent c44089b commit 26c9102
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,14 @@ proc processLockedDependencies(pkgInfo: PackageInfo, options: Options):
raise nimbleError("Unsatisfied dependency: " & pkgInfo.basicInfo.name)

proc getDownloadInfo*(pv: PkgTuple, options: Options,
doPrompt: bool): (DownloadMethod, string,
doPrompt: bool, ignorePackageCache = false): (DownloadMethod, string,
Table[string, string]) =
if pv.name.isURL:
let (url, metadata) = getUrlData(pv.name)
return (checkUrlType(url), url, metadata)
else:
var pkg = initPackage()
if getPackage(pv.name, options, pkg):
if getPackage(pv.name, options, pkg, ignorePackageCache):
let (url, metadata) = getUrlData(pkg.url)
return (pkg.downloadMethod, url, metadata)
else:
Expand All @@ -622,7 +622,8 @@ proc getDownloadInfo*(pv: PkgTuple, options: Options,
# Once we've refreshed, try again, but don't prompt if not found
# (as we've already refreshed and a failure means it really
# isn't there)
return getDownloadInfo(pv, options, false)
# Also ignore the package cache so the old info isn't used
return getDownloadInfo(pv, options, false, true)
else:
raise nimbleError(pkgNotFoundMsg(pv))

Expand Down
10 changes: 5 additions & 5 deletions src/nimblepkg/packageinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ proc fetchList*(list: PackageList, options: Options) =
# Cache after first call
var
gPackageJson: Table[string, JsonNode]
proc readPackageList(name: string, options: Options): JsonNode =
proc readPackageList(name: string, options: Options, ignorePackageCache = false): JsonNode =
# If packages.json is not present ask the user if they want to download it.
if gPackageJson.hasKey(name):
if (not ignorePackageCache) and gPackageJson.hasKey(name):
return gPackageJson[name]

if needsRefresh(options):
Expand All @@ -204,7 +204,7 @@ proc readPackageList(name: string, options: Options): JsonNode =
name.toLowerAscii() & ".json")
return gPackageJson[name]

proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool
proc getPackage*(pkg: string, options: Options, resPkg: var Package, ignorePackageCache = false): bool
proc resolveAlias(pkg: Package, options: Options): Package =
result = pkg
# Resolve alias.
Expand All @@ -215,7 +215,7 @@ proc resolveAlias(pkg: Package, options: Options): Package =
raise nimbleError("Alias for package not found: " &
pkg.alias)

proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool =
proc getPackage*(pkg: string, options: Options, resPkg: var Package, ignorePackageCache = false): bool =
## Searches any packages.json files defined in ``options.config.packageLists``
## Saves the found package into ``resPkg``.
##
Expand All @@ -226,7 +226,7 @@ proc getPackage*(pkg: string, options: Options, resPkg: var Package): bool =
## Aliases are handled and resolved.
for name, list in options.config.packageLists:
display("Reading", "$1 package list" % name, priority = LowPriority)
let packages = readPackageList(name, options)
let packages = readPackageList(name, options, ignorePackageCache)
for p in packages:
if normalize(p["name"].str) == normalize(pkg):
resPkg = p.fromJson()
Expand Down
16 changes: 16 additions & 0 deletions tests/tissues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,19 @@ suite "issues":
else:
"libissue941.so"
check output.contains(expectedBinaryName)

test "issue #953 (Use refreshed package list)":
# Remove all packages from the json file so it needs to be refreshed
writeFile(installDir / "packages_official.json", "[]")
removeDir(installDir / "pkgs2")

let (output, exitCode) = execNimble("install", "-y", "fusion")
let lines = output.strip.processOutput()
# Test that it needed to refresh packages and that it installed
check:
exitCode == QuitSuccess
inLines(lines, "check internet for updated packages")
inLines(lines, "fusion installed successfully")

# Clean up package file
check execNimble(["refresh"]).exitCode == QuitSuccess

0 comments on commit 26c9102

Please sign in to comment.