Skip to content

Commit 0c14c5f

Browse files
authored
Fix: Hash detection affects all Search results (#107)
## Description The current Hash check in the code will directly cause the program to throw an error. When using Search, if there is even one Hash check failure, no information can be displayed. I have fixed this issue and retained the error throw in the Install section. However, I don't think it's necessary to make the program fail to run specifically because of this issue. The possible useful solutions I have thought of, which I can modify if you are willing to accept, are: 1. Automatically ignore all packages with Hash check failures. 2. Give users the right to choose, informing them that the content does not match, but they can still install it.
1 parent e9f39ea commit 0c14c5f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

nupm/install.nu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ def fetch-package [
207207
throw-error $'No package matching version `($version)`'
208208
}
209209

210+
if $pkg.hash_mismatch == true {
211+
throw-error ($'Content of package file ($pkg.path)'
212+
+ $' does not match expected hash')
213+
}
214+
210215
print $pkg
211216

212217
if $pkg.type == 'git' {

nupm/search.nu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export def main [
1010
--pkg-version(-v): string # Package version to install
1111
--exact-match(-e) # Match package name exactly
1212
]: nothing -> table {
13-
search-package $package --registry $registry --exact-match=$exact_match
13+
let result = search-package $package --registry $registry --exact-match=$exact_match
1414
| flatten
1515
| each {|row|
1616
{
@@ -24,4 +24,6 @@ export def main [
2424
}
2525
}
2626
| filter-by-version $pkg_version
27+
28+
return $result
2729
}

nupm/utils/registry.nu

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,15 @@ export def search-package [
8686

8787
let new_hash = open $pkg_file_path | to nuon | hash-fn
8888

89-
if $new_hash != $row.hash {
90-
throw-error ($'Content of package file ($pkg_file_path)'
91-
+ $' does not match expected hash ($row.hash)')
92-
}
93-
94-
open $pkg_file_path
89+
open $pkg_file_path | insert hash_mismatch ($new_hash != $row.hash)
9590
}
91+
| compact
9692
| flatten
9793

9894
{
9995
registry_name: $name
10096
registry_path: $registry.path
101-
pkgs: $pkgs
97+
pkgs: $pkgs,
10298
}
10399
}
104100
| compact

0 commit comments

Comments
 (0)