Skip to content

Commit 9655894

Browse files
committed
add hash_mismatch field to registry
1 parent dd23d9a commit 9655894

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
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 --skip-dirty-pkg
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: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use misc.nu [check-cols url hash-file]
88
export const REG_COLS = [ name path hash ]
99

1010
# Columns of a registry package file
11-
export const REG_PKG_COLS = [ name version path type info ]
11+
export const REG_PKG_COLS = [ name version path type info hash_mismatch ]
1212

1313
# Search for a package in a registry
1414
export def search-package [
1515
package: string # Name of the package
1616
--registry: string # Which registry to use (name or path)
1717
--exact-match # Searched package name must match exactly
18-
--skip-dirty-pkg # Skip packages with failed hash checks
1918
] -> table {
2019
let registries = if (not ($registry | is-empty)) and ($registry in $env.NUPM_REGISTRIES) {
2120
# If $registry is a valid column in $env.NUPM_REGISTRIES, use that
@@ -87,17 +86,7 @@ export def search-package [
8786

8887
let new_hash = $pkg_file_path | hash-file
8988

90-
let dirty = $new_hash != $row.hash
91-
if $new_hash != $row.hash {
92-
if $skip_dirty_pkg {
93-
null
94-
} else {
95-
throw-error ($'Content of package file `($url_or_path)'
96-
+ $' does not match expected hash `($row.hash)`.')
97-
}
98-
} else {
99-
open $pkg_file_path | insert dirty $dirty
100-
}
89+
open $pkg_file_path | insert hash_mismatch ($new_hash != $row.hash)
10190
}
10291
| compact
10392
| flatten

0 commit comments

Comments
 (0)