Class: RubyLens::Index::GitPackageSource

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/index/git_package_source.rb

Overview

Resolves a git-sourced lockfile entry into the exact files RubyLens may index.

Git checkouts carry more authority than RubyGems packages: the gemspec is code from the checkout that names its own require paths, and the tree may hold symlinks pointing anywhere on disk. Every path here is therefore resolved and re-checked against the canonical package root before it becomes indexable, and any breach ends the package rather than narrowing it, so a partially trusted tree can never contribute files.

Defined Under Namespace

Classes: NixStoreProvider, PackagePaths, Resolution

Constant Summary collapse

UnsafeRequirePath =
Class.new(StandardError)
UnsafePackageFile =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(lockfile:) ⇒ GitPackageSource

: (lockfile: Pathname) -> void



53
54
55
56
57
# File 'lib/rubylens/index/git_package_source.rb', line 53

def initialize(lockfile:)
  @lockfile = lockfile
  @nix_store_provider = NixStoreProvider.new
  @specification_indexes = {}.compare_by_identity
end

Instance Method Details

#resolve(locked) ⇒ Object

Returns a Resolution, or a Symbol naming why the package was skipped. Callers own how a skip is reported, so every reason surfaces through the same warning vocabulary as the other package sources.

: (Bundler::LazySpecification) -> (Resolution | Symbol)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rubylens/index/git_package_source.rb', line 64

def resolve(locked)
  source = locked.source
  return :local_only_required if source.allow_git_ops?

  checkout = checkout_path(source)
  return :checkout_unavailable unless checkout.directory?

  index = (@specification_indexes[source] ||= specification_index(source, checkout))
  specification = index.search(locked).first
  return :specification_unavailable unless specification

  paths = package_paths(specification, checkout)
  return :unsafe_specification_root unless paths

  Resolution.new(
    root: paths.canonical_root,
    files: indexable_files(paths, specification.require_paths).freeze,
  )
rescue UnsafeRequirePath
  :unsafe_require_paths
rescue UnsafePackageFile
  :unsafe_package_files
rescue Bundler::BundlerError, Gem::Exception
  :specification_unreadable
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
  :checkout_unavailable
end