debeasy 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/debeasy.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_dependency "libarchive"
26
+ spec.add_dependency "ruby-filemagic"
26
27
  end
@@ -1,10 +1,14 @@
1
1
  require 'libarchive'
2
+ require 'filemagic'
2
3
 
3
4
  module Debeasy
5
+ class Error < RuntimeError; end
6
+ class NotAPackageError < Error; end
7
+
4
8
  class Package
5
9
 
6
- attr_reader :path, :package
7
- attr_reader :control_file_contents
10
+ attr_reader :path, :package_file
11
+ attr_reader :control_file_contents, :filelist
8
12
  attr_reader :preinst_contents, :prerm_contents
9
13
  attr_reader :postinst_contents, :postrm_contents
10
14
 
@@ -15,8 +19,10 @@ module Debeasy
15
19
 
16
20
  def initialize(path)
17
21
  @path = path
18
- @package = Archive.read_open_filename(path)
22
+ raise NotAPackageError, "#{path} is not a Debian package" unless is_package_file?
23
+ @package_file = Archive.read_open_filename(path)
19
24
  @fields = {}
25
+ @filelist = []
20
26
  extract_files
21
27
  parse_control_file
22
28
  end
@@ -33,13 +39,23 @@ module Debeasy
33
39
 
34
40
  private
35
41
 
36
- # Poke inside the package to find the control file,
37
- # and the pre/post install scripts.
42
+ def is_package_file?
43
+ fm = FileMagic.new
44
+ if fm.file(@path) =~ /Debian binary package/
45
+ true
46
+ else
47
+ false
48
+ end
49
+ end
38
50
 
51
+ # Poke inside the package to find the control file,
52
+ # the pre/post install scripts, and a list of
53
+ # all the files it will deploy.
54
+
39
55
  def extract_files
40
- while file = @package.next_header
56
+ while file = @package_file.next_header
41
57
  if file.pathname == "control.tar.gz"
42
- control_tar_gz = Archive.read_open_memory(@package.read_data)
58
+ control_tar_gz = Archive.read_open_memory(@package_file.read_data)
43
59
  while control_entry = control_tar_gz.next_header
44
60
  case control_entry.pathname
45
61
  when "./control"
@@ -55,6 +71,12 @@ module Debeasy
55
71
  end
56
72
  end
57
73
  end
74
+ if file.pathname == "data.tar.gz"
75
+ data_tar_gz = Archive.read_open_memory(@package_file.read_data)
76
+ while data_entry = data_tar_gz.next_header
77
+ @filelist << data_entry.pathname.sub(/^\./, "")
78
+ end
79
+ end
58
80
  end
59
81
  end
60
82
 
@@ -1,3 +1,3 @@
1
1
  module Debeasy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debeasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: ruby-filemagic
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: ! "Debeasy is a simple gem that allows you to\n programmatically
63
79
  read Debian packages with very\n little effort."
64
80
  email: