Skip to content

Commit

Permalink
Fix: Hash detection affects all Search results
Browse files Browse the repository at this point in the history
  • Loading branch information
mrxiaozhuox committed Nov 21, 2024
1 parent 7e3e577 commit c424b13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 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.dirty {
throw-error ($'Content of package file `($pkg.path)'
+ $'` does not match expected hash.')
}

print $pkg

if $pkg.type == 'git' {
Expand Down
22 changes: 13 additions & 9 deletions nupm/search.nu
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ export def main [
search-package $package --registry $registry --exact-match=$exact_match
| flatten
| each {|row|
{
registry_name: $row.registry_name
registry_path: $row.registry_path
name: $row.pkgs.name
version: $row.pkgs.version
path: $row.pkgs.path
type: $row.pkgs.type
info: $row.pkgs.info
if $row.pkgs.dirty {
null
} else {
{
registry_name: $row.registry_name
registry_path: $row.registry_path
name: $row.pkgs.name
version: $row.pkgs.version
path: $row.pkgs.path
type: $row.pkgs.type
info: $row.pkgs.info
}
}
}
| filter-by-version $pkg_version
| compact | filter-by-version $pkg_version
}
12 changes: 5 additions & 7 deletions nupm/utils/registry.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 dirty ]

# Search for a package in a registry
export def search-package [
Expand Down Expand Up @@ -86,19 +86,17 @@ export def search-package [

let new_hash = $pkg_file_path | hash-file

if $new_hash != $row.hash {
throw-error ($'Content of package file ($pkg_file_path)'
+ $' does not match expected hash ($row.hash)')
}
# check package hash
let dirty = $new_hash != $row.hash

open $pkg_file_path
open $pkg_file_path | insert dirty $dirty
}
| flatten

{
registry_name: $name
registry_path: $registry.path
pkgs: $pkgs
pkgs: $pkgs,
}
}
| compact
Expand Down

0 comments on commit c424b13

Please sign in to comment.