Skip to content

Commit

Permalink
add hash_mismatch field to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxiaozhuox committed Dec 22, 2024
1 parent dd23d9a commit 9655894
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
5 changes: 5 additions & 0 deletions nupm/install.nu
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def fetch-package [
throw-error $'No package matching version `($version)`'
}

if $pkg.hash_mismatch != true {
throw-error ($'Content of package file ($pkg.path)'
+ $' does not match expected hash')
}

print $pkg

if $pkg.type == 'git' {
Expand Down
4 changes: 3 additions & 1 deletion nupm/search.nu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export def main [
--pkg-version(-v): string # Package version to install
--exact-match(-e) # Match package name exactly
]: nothing -> table {
search-package $package --registry $registry --exact-match=$exact_match --skip-dirty-pkg
let result = search-package $package --registry $registry --exact-match=$exact_match
| flatten
| each {|row|
{
Expand All @@ -24,4 +24,6 @@ export def main [
}
}
| filter-by-version $pkg_version

return $result
}
15 changes: 2 additions & 13 deletions nupm/utils/registry.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use misc.nu [check-cols url hash-file]
export const REG_COLS = [ name path hash ]

# Columns of a registry package file
export const REG_PKG_COLS = [ name version path type info ]
export const REG_PKG_COLS = [ name version path type info hash_mismatch ]

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

let new_hash = $pkg_file_path | hash-file

let dirty = $new_hash != $row.hash
if $new_hash != $row.hash {
if $skip_dirty_pkg {
null
} else {
throw-error ($'Content of package file `($url_or_path)'
+ $' does not match expected hash `($row.hash)`.')
}
} else {
open $pkg_file_path | insert dirty $dirty
}
open $pkg_file_path | insert hash_mismatch ($new_hash != $row.hash)
}
| compact
| flatten
Expand Down

0 comments on commit 9655894

Please sign in to comment.