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 this string

github.com/git/git/blob/v2.20.1/bundle.c#L15

"# v2 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.



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

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



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

def filename
  @filename
end

Class Method Details

.check!(filename) ⇒ Object



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

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

Instance Method Details

#check!Object

Raises:



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

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

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