poise-archive 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -0
- data/README.md +3 -0
- data/lib/poise_archive/archive_providers/tar.rb +76 -70
- data/lib/poise_archive/bzip2.rb +16 -0
- data/lib/poise_archive/bzip2/LICENSE +25 -0
- data/lib/poise_archive/bzip2/constants.rb +83 -0
- data/lib/poise_archive/bzip2/crc.rb +73 -0
- data/lib/poise_archive/bzip2/decompressor.rb +704 -0
- data/lib/poise_archive/bzip2/input_data.rb +43 -0
- data/lib/poise_archive/bzip2/output_data.rb +57 -0
- data/lib/poise_archive/version.rb +1 -1
- data/test/spec/archive_providers/tar_spec.rb +44 -89
- metadata +9 -2
@@ -0,0 +1,43 @@
|
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
|
+
|
6
|
+
|
7
|
+
class PoiseArchive::Bzip2::InputData
|
8
|
+
|
9
|
+
include PoiseArchive::Bzip2::Constants
|
10
|
+
|
11
|
+
attr_reader :base, :cftab, :get_and_move_to_front_decode_yy, :in_use,
|
12
|
+
:limit, :ll8, :min_lens, :perm, :receive_decoding_tables_pos,
|
13
|
+
:selector, :selector_mtf, :seq_to_unseq, :temp_char_array_2d,
|
14
|
+
:unzftab, :tt
|
15
|
+
|
16
|
+
def initialize(block_size)
|
17
|
+
@in_use = Array.new 256, false
|
18
|
+
|
19
|
+
@seq_to_unseq = Array.new 256, 0
|
20
|
+
@selector = Array.new MAX_SELECTORS, 0
|
21
|
+
@selector_mtf = Array.new MAX_SELECTORS, 0
|
22
|
+
|
23
|
+
@unzftab = Array.new 256, 0
|
24
|
+
|
25
|
+
@base = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
26
|
+
@limit = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
27
|
+
@perm = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
28
|
+
@min_lens = Array.new N_GROUPS, 0
|
29
|
+
|
30
|
+
@cftab = Array.new 257, 0
|
31
|
+
@get_and_move_to_front_decode_yy = Array.new 256
|
32
|
+
@temp_char_array_2d = Array.new(N_GROUPS) { Array.new(MAX_ALPHA_SIZE, 0) }
|
33
|
+
@receive_decoding_tables_pos = Array.new N_GROUPS, 0
|
34
|
+
|
35
|
+
@ll8 = Array.new block_size * BASEBLOCKSIZE
|
36
|
+
end
|
37
|
+
|
38
|
+
def init_tt(size)
|
39
|
+
@tt = Array.new(size) if @tt.nil? || @tt.size < size
|
40
|
+
@tt
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
|
+
|
6
|
+
|
7
|
+
class PoiseArchive::Bzip2::OutputData
|
8
|
+
|
9
|
+
include PoiseArchive::Bzip2::Constants
|
10
|
+
|
11
|
+
attr_reader :block, :ftab, :fmap, :generate_mtf_values_yy, :heap, :in_use,
|
12
|
+
:main_sort_big_done, :main_sort_copy, :main_sort_running_order,
|
13
|
+
:mtf_freq, :parent, :quadrant, :selector, :selector_mtf,
|
14
|
+
:send_mtf_values_code, :send_mtf_values_cost,
|
15
|
+
:send_mtf_values_fave, :send_mtf_values_len,
|
16
|
+
:send_mtf_values_rfreq, :send_mtf_values2_pos,
|
17
|
+
:send_mtf_values4_in_use_16, :sfmap, :stack_dd, :stack_hh,
|
18
|
+
:stack_ll, :unseq_to_seq, :weight
|
19
|
+
|
20
|
+
def initialize(block_size)
|
21
|
+
n = block_size * BASEBLOCKSIZE
|
22
|
+
@block = Array.new n + 1 + NUM_OVERSHOOT_BYTES, 0
|
23
|
+
@fmap = Array.new n, 0
|
24
|
+
@selector = Array.new MAX_SELECTORS
|
25
|
+
@selector_mtf = Array.new MAX_SELECTORS
|
26
|
+
@sfmap = Array.new 2 * n
|
27
|
+
@quadrant = @sfmap
|
28
|
+
|
29
|
+
@in_use = Array.new 256
|
30
|
+
@mtf_freq = Array.new MAX_ALPHA_SIZE, 0
|
31
|
+
@unseq_to_seq = Array.new 256
|
32
|
+
|
33
|
+
@generate_mtf_values_yy = Array.new 256
|
34
|
+
@send_mtf_values_code = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
35
|
+
@send_mtf_values_cost = Array.new N_GROUPS
|
36
|
+
@send_mtf_values_fave = Array.new N_GROUPS
|
37
|
+
@send_mtf_values_len = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
38
|
+
@send_mtf_values_rfreq = Array.new(N_GROUPS) { Array.new MAX_ALPHA_SIZE }
|
39
|
+
@send_mtf_values2_pos = Array.new N_GROUPS
|
40
|
+
@send_mtf_values4_in_use_16 = Array.new 16
|
41
|
+
|
42
|
+
@stack_dd = Array.new QSORT_STACK_SIZE
|
43
|
+
@stack_hh = Array.new QSORT_STACK_SIZE
|
44
|
+
@stack_ll = Array.new QSORT_STACK_SIZE
|
45
|
+
|
46
|
+
@main_sort_big_done = Array.new 256
|
47
|
+
@main_sort_copy = Array.new 256
|
48
|
+
@main_sort_running_order = Array.new 256
|
49
|
+
|
50
|
+
@heap = Array.new MAX_ALPHA_SIZE + 2
|
51
|
+
@parent = Array.new MAX_ALPHA_SIZE + 2
|
52
|
+
@weight = Array.new MAX_ALPHA_SIZE + 2
|
53
|
+
|
54
|
+
@ftab = Array.new 65537
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -16,119 +16,74 @@
|
|
16
16
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
|
+
FIXTURES_PATH = File.expand_path('../../../cookbook/files', __FILE__)
|
20
|
+
|
19
21
|
describe PoiseArchive::ArchiveProviders::Tar do
|
20
22
|
step_into(:poise_archive)
|
21
23
|
|
22
24
|
describe '#action_unpack' do
|
23
|
-
let(:tar_cmd) { [] }
|
24
25
|
let(:archive_provider) { chef_run.poise_archive('myapp').provider_for_action(:unpack) }
|
25
26
|
before do
|
26
|
-
allow(described_class).to receive(:mktmpdir).and_yield('/test')
|
27
|
+
# allow(described_class).to receive(:mktmpdir).and_yield('/test')
|
28
|
+
expect(Dir).to receive(:mkdir).and_call_original
|
27
29
|
allow(Dir).to receive(:entries).and_call_original
|
28
|
-
allow(Dir).to receive(:entries).with('/
|
29
|
-
expect_any_instance_of(described_class).to receive(:poise_shell_out!).with(tar_cmd, cwd: '/test', group: nil, user: nil)
|
30
|
-
expect_any_instance_of(described_class).to receive(:entries_at_depth).with('/test', 1).and_return(%w{/test/myapp/bin /test/myapp/src})
|
31
|
-
expect(File).to receive(:rename).with('/test/myapp/bin', '/root/myapp/bin')
|
32
|
-
expect(File).to receive(:rename).with('/test/myapp/src', '/root/myapp/src')
|
30
|
+
allow(Dir).to receive(:entries).with('/test/myapp').and_return(%w{. ..})
|
31
|
+
# expect_any_instance_of(described_class).to receive(:poise_shell_out!).with(tar_cmd, cwd: '/test', group: nil, user: nil)
|
32
|
+
# expect_any_instance_of(described_class).to receive(:entries_at_depth).with('/test', 1).and_return(%w{/test/myapp/bin /test/myapp/src})
|
33
|
+
# expect(File).to receive(:rename).with('/test/myapp/bin', '/root/myapp/bin')
|
34
|
+
# expect(File).to receive(:rename).with('/test/myapp/src', '/root/myapp/src')
|
35
|
+
allow(File).to receive(:open).and_call_original
|
36
|
+
allow(File).to receive(:open).with('/test/myapp-1.0.0.tar', 'rb') { File.open(File.join(FIXTURES_PATH, 'myapp-1.0.0.tar')) }
|
37
|
+
allow(File).to receive(:open).with('/test/myapp-1.0.0.tar.gz', 'rb') { File.open(File.join(FIXTURES_PATH, 'myapp-1.0.0.tar.gz')) }
|
38
|
+
allow(File).to receive(:open).with('/test/myapp-1.0.0.tgz', 'rb') { File.open(File.join(FIXTURES_PATH, 'myapp-1.0.0.tar.gz')) }
|
39
|
+
allow(File).to receive(:open).with('/test/myapp-1.0.0.tar.bz2', 'rb') { File.open(File.join(FIXTURES_PATH, 'myapp-1.0.0.tar.bz2')) }
|
40
|
+
allow(File).to receive(:open).with('/test/myapp-1.0.0.tbz2', 'rb') { File.open(File.join(FIXTURES_PATH, 'myapp-1.0.0.tar.bz2')) }
|
33
41
|
end
|
34
42
|
|
35
|
-
|
36
|
-
let(:tar_cmd) { %w{tar -xvf /root/myapp.tar} }
|
43
|
+
RSpec.shared_examples 'a poise_archive test' do |ext|
|
37
44
|
recipe do
|
38
45
|
poise_archive 'myapp' do
|
39
|
-
path
|
46
|
+
path "/test/myapp-1.0.0.#{ext}"
|
47
|
+
destination '/test/myapp'
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
recipe do
|
49
|
-
poise_archive 'myapp' do
|
50
|
-
path '/root/myapp.tar.gz'
|
51
|
-
end
|
51
|
+
def expect_file(path, content, mode)
|
52
|
+
fake_file = double("file for #{path}")
|
53
|
+
expect(fake_file).to receive(:write).with(content)
|
54
|
+
allow(File).to receive(:open).with(path, 'wb', mode).and_yield(fake_file)
|
55
|
+
expect(FileUtils).to receive(:chown).with(nil, nil, path)
|
52
56
|
end
|
53
57
|
|
54
|
-
it
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
58
|
+
it do
|
59
|
+
expect_file('/test/myapp/LICENSE', "This is in the public domain.\n", 0644)
|
60
|
+
expect_file('/test/myapp/README', "This is a project!\n\n", 0644)
|
61
|
+
expect(Dir).to receive(:mkdir).with('/test/myapp/src', 0755)
|
62
|
+
expect(FileUtils).to receive(:chown).with(nil, nil, '/test/myapp/src')
|
63
|
+
expect_file('/test/myapp/src/main.c', "int main(int argc, char **argv)\n{\n return 0;\n}\n\n", 0644)
|
64
|
+
run_chef
|
65
|
+
expect(archive_provider).to be_a described_class
|
63
66
|
end
|
67
|
+
end
|
64
68
|
|
65
|
-
|
66
|
-
|
69
|
+
context 'with a .tar path' do
|
70
|
+
it_should_behave_like 'a poise_archive test', 'tar'
|
71
|
+
end # /context with a .tar path
|
67
72
|
|
68
|
-
context 'with a .tar.
|
69
|
-
|
70
|
-
|
71
|
-
poise_archive 'myapp' do
|
72
|
-
path '/root/myapp.tar.bz2'
|
73
|
-
end
|
74
|
-
end
|
73
|
+
context 'with a .tar.gz path' do
|
74
|
+
it_should_behave_like 'a poise_archive test', 'tar.gz'
|
75
|
+
end # /context with a .tar.gz path
|
75
76
|
|
76
|
-
|
77
|
+
context 'with a .tar.bz2 path' do
|
78
|
+
it_should_behave_like 'a poise_archive test', 'tar.bz2'
|
77
79
|
end # /context with a .tar.bz2 path
|
78
80
|
|
79
81
|
context 'with a .tgz path' do
|
80
|
-
|
81
|
-
recipe do
|
82
|
-
poise_archive 'myapp' do
|
83
|
-
path '/root/myapp.tgz'
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
it { expect(archive_provider).to be_a described_class }
|
82
|
+
it_should_behave_like 'a poise_archive test', 'tgz'
|
88
83
|
end # /context with a .tgz path
|
89
84
|
|
90
|
-
context 'with a .
|
91
|
-
|
92
|
-
|
93
|
-
poise_archive 'myapp' do
|
94
|
-
path '/root/myapp.tbz'
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
it { expect(archive_provider).to be_a described_class }
|
99
|
-
end # /context with a .tbz path
|
85
|
+
context 'with a .tbz2 path' do
|
86
|
+
it_should_behave_like 'a poise_archive test', 'tbz2'
|
87
|
+
end # /context with a .tbz2 path
|
100
88
|
end # /describe #action_unpack
|
101
|
-
|
102
|
-
describe '#entries_at_depth' do
|
103
|
-
let(:depth) { nil }
|
104
|
-
subject { described_class.new(nil, nil).send(:entries_at_depth, '/test', depth) }
|
105
|
-
before do
|
106
|
-
allow(Dir).to receive(:entries).and_call_original
|
107
|
-
allow(Dir).to receive(:entries).with('/test').and_return(%w{. .. a b})
|
108
|
-
allow(Dir).to receive(:entries).with('/test/a').and_return(%w{. .. aa ab})
|
109
|
-
allow(Dir).to receive(:entries).with('/test/a/aa').and_return(%w{. .. aaa})
|
110
|
-
allow(Dir).to receive(:entries).with('/test/a/ab').and_return(%w{. .. aba abb})
|
111
|
-
allow(File).to receive(:directory?).and_call_original
|
112
|
-
allow(File).to receive(:directory?).with('/test').and_return(true)
|
113
|
-
allow(File).to receive(:directory?).with('/test/a').and_return(true)
|
114
|
-
allow(File).to receive(:directory?).with('/test/b').and_return(false)
|
115
|
-
allow(File).to receive(:directory?).with('/test/a/aa').and_return(true)
|
116
|
-
allow(File).to receive(:directory?).with('/test/a/ab').and_return(true)
|
117
|
-
end
|
118
|
-
|
119
|
-
context 'with depth 0' do
|
120
|
-
let(:depth) { 0 }
|
121
|
-
it { is_expected.to eq %w{/test/a /test/b} }
|
122
|
-
end # /context with depth 0
|
123
|
-
|
124
|
-
context 'with depth 1' do
|
125
|
-
let(:depth) { 1 }
|
126
|
-
it { is_expected.to eq %w{/test/a/aa /test/a/ab} }
|
127
|
-
end # /context with depth 1
|
128
|
-
|
129
|
-
context 'with depth 2' do
|
130
|
-
let(:depth) { 2 }
|
131
|
-
it { is_expected.to eq %w{/test/a/aa/aaa /test/a/ab/aba /test/a/ab/abb} }
|
132
|
-
end # /context with depth 2
|
133
|
-
end # /describe #entries_at_depth
|
134
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poise-archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Kantrowitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: halite
|
@@ -73,6 +73,13 @@ files:
|
|
73
73
|
- lib/poise_archive/archive_providers/base.rb
|
74
74
|
- lib/poise_archive/archive_providers/tar.rb
|
75
75
|
- lib/poise_archive/archive_providers/zip.rb
|
76
|
+
- lib/poise_archive/bzip2.rb
|
77
|
+
- lib/poise_archive/bzip2/LICENSE
|
78
|
+
- lib/poise_archive/bzip2/constants.rb
|
79
|
+
- lib/poise_archive/bzip2/crc.rb
|
80
|
+
- lib/poise_archive/bzip2/decompressor.rb
|
81
|
+
- lib/poise_archive/bzip2/input_data.rb
|
82
|
+
- lib/poise_archive/bzip2/output_data.rb
|
76
83
|
- lib/poise_archive/cheftie.rb
|
77
84
|
- lib/poise_archive/resources.rb
|
78
85
|
- lib/poise_archive/resources/poise_archive.rb
|