Class: Gitlab::Git::BundleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/bundle_file.rb

Constant Summary collapse

MAGIC =

All git bundle files start with one of these strings

https://github.com/git/git/blob/v2.50.1/bundle.c#L24

"# v2 git bundle\n"
MAGIC_V3 =
"# v3 git bundle\n"
InvalidBundleError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ BundleFile

Returns a new instance of BundleFile.



20
21
22
# File 'lib/gitlab/git/bundle_file.rb', line 20

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



14
15
16
# File 'lib/gitlab/git/bundle_file.rb', line 14

def filename
  @filename
end

Class Method Details

.check!(filename) ⇒ Object



16
17
18
# File 'lib/gitlab/git/bundle_file.rb', line 16

def self.check!(filename)
  new(filename).check!
end

Instance Method Details

#check!Object

Raises:



24
25
26
27
28
# File 'lib/gitlab/git/bundle_file.rb', line 24

def check!
  data = File.open(filename, 'r') { |f| f.read(MAGIC.size) }

  raise InvalidBundleError, 'Invalid bundle file' unless data == MAGIC || data == MAGIC_V3
end