unpack 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +5 -0
  3. data/Gemfile +4 -0
  4. data/README.markdown +85 -0
  5. data/Rakefile +2 -0
  6. data/bin/unrar +0 -0
  7. data/lib/unpack.rb +146 -0
  8. data/lib/unpack/container.rb +15 -0
  9. data/spec/data/o_files/some_zip_files.zip +0 -0
  10. data/spec/data/o_files/test_package.rar +0 -0
  11. data/spec/data/rar/110_accessible_.rar +1 -0
  12. data/spec/data/rar/120_accessible_.rar +1 -0
  13. data/spec/data/rar/167_accessible_.rar +1 -0
  14. data/spec/data/rar/777_accessible_.rar +1 -0
  15. data/spec/data/rar/918_accessible_.rar +1 -0
  16. data/spec/data/rar/cd1/112_okey_.rar +1 -0
  17. data/spec/data/rar/cd1/129_okey_.rar +1 -0
  18. data/spec/data/rar/cd1/199_okey_.rar +1 -0
  19. data/spec/data/rar/cd1/228_okey_.rar +1 -0
  20. data/spec/data/rar/cd1/263_okey_.rar +1 -0
  21. data/spec/data/rar/cd1/325_okey_.rar +1 -0
  22. data/spec/data/rar/cd1/329_okey_.rar +1 -0
  23. data/spec/data/rar/cd1/333_okey_.rar +1 -0
  24. data/spec/data/rar/cd1/364_okey_.rar +1 -0
  25. data/spec/data/rar/cd1/390_okey_.rar +1 -0
  26. data/spec/data/rar/cd1/462_okey_.rar +1 -0
  27. data/spec/data/rar/cd1/515_okey_.rar +1 -0
  28. data/spec/data/rar/cd1/572_okey_.rar +1 -0
  29. data/spec/data/rar/cd1/573_okey_.rar +1 -0
  30. data/spec/data/rar/cd1/5_okey_.rar +1 -0
  31. data/spec/data/rar/cd1/627_okey_.rar +1 -0
  32. data/spec/data/rar/cd1/674_okey_.rar +1 -0
  33. data/spec/data/rar/cd1/682_okey_.rar +1 -0
  34. data/spec/data/rar/cd1/690_okey_.rar +1 -0
  35. data/spec/data/rar/cd1/698_okey_.rar +1 -0
  36. data/spec/data/rar/cd1/817_okey_.rar +1 -0
  37. data/spec/data/rar/cd1/828_okey_.rar +1 -0
  38. data/spec/data/rar/cd1/840_okey_.rar +1 -0
  39. data/spec/data/rar/cd1/920_okey_.rar +1 -0
  40. data/spec/data/rar/cd1/925_okey_.rar +1 -0
  41. data/spec/data/rar/cd1/974_okey_.rar +1 -0
  42. data/spec/data/rar/cd1/978_okey_.rar +1 -0
  43. data/spec/data/rar/cd1/982_okey_.rar +1 -0
  44. data/spec/data/rar/cd1/988_okey_.rar +1 -0
  45. data/spec/data/rar/cd1/998_okey_.rar +1 -0
  46. data/spec/data/rar/cd1/Unreachable/117_not_.rar +1 -0
  47. data/spec/data/rar/cd1/Unreachable/12_not_.rar +1 -0
  48. data/spec/data/rar/cd1/Unreachable/171_not_.rar +1 -0
  49. data/spec/data/rar/cd1/Unreachable/178_not_.rar +1 -0
  50. data/spec/data/rar/cd1/Unreachable/179_not_.rar +1 -0
  51. data/spec/data/rar/cd1/Unreachable/202_not_.rar +1 -0
  52. data/spec/data/rar/cd1/Unreachable/214_not_.rar +1 -0
  53. data/spec/data/rar/cd1/Unreachable/423_not_.rar +1 -0
  54. data/spec/data/rar/cd1/Unreachable/46_not_.rar +1 -0
  55. data/spec/data/rar/cd1/Unreachable/477_not_.rar +1 -0
  56. data/spec/data/rar/cd1/Unreachable/499_not_.rar +1 -0
  57. data/spec/data/rar/cd1/Unreachable/531_not_.rar +1 -0
  58. data/spec/data/rar/cd1/Unreachable/536_not_.rar +1 -0
  59. data/spec/data/rar/cd1/Unreachable/554_not_.rar +1 -0
  60. data/spec/data/rar/cd1/Unreachable/556_not_.rar +1 -0
  61. data/spec/data/rar/cd1/Unreachable/564_not_.rar +1 -0
  62. data/spec/data/rar/cd1/Unreachable/569_not_.rar +1 -0
  63. data/spec/data/rar/cd1/Unreachable/608_not_.rar +1 -0
  64. data/spec/data/rar/cd1/Unreachable/614_not_.rar +1 -0
  65. data/spec/data/rar/cd1/Unreachable/634_not_.rar +1 -0
  66. data/spec/data/rar/cd1/Unreachable/644_not_.rar +1 -0
  67. data/spec/data/rar/cd1/Unreachable/708_not_.rar +1 -0
  68. data/spec/data/rar/cd1/Unreachable/756_not_.rar +1 -0
  69. data/spec/data/rar/cd1/Unreachable/802_not_.rar +1 -0
  70. data/spec/data/rar/cd1/Unreachable/815_not_.rar +1 -0
  71. data/spec/data/rar/cd1/Unreachable/833_not_.rar +1 -0
  72. data/spec/data/rar/cd1/Unreachable/84_not_.rar +1 -0
  73. data/spec/data/rar/cd1/Unreachable/92_not_.rar +1 -0
  74. data/spec/data/rar/cd1/Unreachable/936_not_.rar +1 -0
  75. data/spec/data/rar/cd1/Unreachable/939_not_.rar +1 -0
  76. data/spec/data/rar/cd2/102_okey_without_.strange +1 -0
  77. data/spec/data/rar/cd2/111_okey_without_.strange +1 -0
  78. data/spec/data/rar/cd2/14_okey_without_.strange +1 -0
  79. data/spec/data/rar/cd2/242_okey_without_.strange +1 -0
  80. data/spec/data/rar/cd2/244_okey_without_.strange +1 -0
  81. data/spec/data/rar/cd2/248_okey_without_.strange +1 -0
  82. data/spec/data/rar/cd2/278_okey_without_.strange +1 -0
  83. data/spec/data/rar/cd2/283_okey_without_.strange +1 -0
  84. data/spec/data/rar/cd2/310_okey_without_.strange +1 -0
  85. data/spec/data/rar/cd2/439_okey_without_.strange +1 -0
  86. data/spec/data/rar/cd2/453_okey_without_.strange +1 -0
  87. data/spec/data/rar/cd2/461_okey_without_.strange +1 -0
  88. data/spec/data/rar/cd2/476_okey_without_.strange +1 -0
  89. data/spec/data/rar/cd2/484_okey_without_.strange +1 -0
  90. data/spec/data/rar/cd2/491_okey_without_.strange +1 -0
  91. data/spec/data/rar/cd2/507_okey_without_.strange +1 -0
  92. data/spec/data/rar/cd2/518_okey_without_.strange +1 -0
  93. data/spec/data/rar/cd2/609_okey_without_.strange +1 -0
  94. data/spec/data/rar/cd2/613_okey_without_.strange +1 -0
  95. data/spec/data/rar/cd2/633_okey_without_.strange +1 -0
  96. data/spec/data/rar/cd2/644_okey_without_.strange +1 -0
  97. data/spec/data/rar/cd2/682_okey_without_.strange +1 -0
  98. data/spec/data/rar/cd2/706_okey_without_.strange +1 -0
  99. data/spec/data/rar/cd2/767_okey_without_.strange +1 -0
  100. data/spec/data/rar/cd2/788_okey_without_.strange +1 -0
  101. data/spec/data/rar/cd2/801_okey_without_.rar +1 -0
  102. data/spec/data/rar/cd2/808_okey_without_.strange +1 -0
  103. data/spec/data/rar/cd2/837_okey_without_.strange +1 -0
  104. data/spec/data/rar/cd2/919_okey_without_.strange +1 -0
  105. data/spec/data/rar/cd2/93_okey_without_.strange +1 -0
  106. data/spec/data/rar/cd2/980_okey_without_.strange +1 -0
  107. data/spec/data/rar/subdir/133_subtitle_.rar +1 -0
  108. data/spec/data/rar/subdir/169_subtitle_.rar +1 -0
  109. data/spec/data/rar/subdir/22_subtitle_.rar +1 -0
  110. data/spec/data/rar/subdir/483_subtitle_.rar +1 -0
  111. data/spec/data/rar/subdir/639_subtitle_.rar +1 -0
  112. data/spec/data/rar_real/110_real_.file.rar +1 -0
  113. data/spec/data/rar_real/120_real_.file.rar +1 -0
  114. data/spec/data/rar_real/167_real_.file.rar +1 -0
  115. data/spec/data/rar_real/777_real_.file.rar +1 -0
  116. data/spec/data/rar_real/918_real_.file.rar +1 -0
  117. data/spec/data/zip_real/some_zip_files.zip +0 -0
  118. data/spec/spec_helper.rb +7 -0
  119. data/spec/unpack_spec.rb +261 -0
  120. data/unpack.gemspec +21 -0
  121. metadata +321 -0
@@ -0,0 +1 @@
1
+ 569
@@ -0,0 +1 @@
1
+ 726
@@ -0,0 +1 @@
1
+ 538
@@ -0,0 +1 @@
1
+ 235
@@ -0,0 +1 @@
1
+ 190
@@ -0,0 +1 @@
1
+ 721
@@ -0,0 +1 @@
1
+ 428
@@ -0,0 +1 @@
1
+ 325
@@ -0,0 +1 @@
1
+ 483
@@ -0,0 +1 @@
1
+ 671
@@ -0,0 +1 @@
1
+ 472
@@ -0,0 +1 @@
1
+ 840
@@ -0,0 +1 @@
1
+ 881
@@ -0,0 +1 @@
1
+ 808
@@ -0,0 +1 @@
1
+ 744
@@ -0,0 +1 @@
1
+ 272
@@ -0,0 +1 @@
1
+ 520
@@ -0,0 +1 @@
1
+ 757
@@ -0,0 +1 @@
1
+ 179
@@ -0,0 +1 @@
1
+ 777
@@ -0,0 +1 @@
1
+ 269
@@ -0,0 +1 @@
1
+ 329
@@ -0,0 +1 @@
1
+ 308
@@ -0,0 +1 @@
1
+ 846
@@ -0,0 +1 @@
1
+ 521
@@ -0,0 +1 @@
1
+ 919
@@ -0,0 +1 @@
1
+ 892
@@ -0,0 +1 @@
1
+ 903
@@ -0,0 +1 @@
1
+ 781
@@ -0,0 +1 @@
1
+ 364
@@ -0,0 +1 @@
1
+ 554
@@ -0,0 +1 @@
1
+ 411
@@ -0,0 +1 @@
1
+ 857
@@ -0,0 +1 @@
1
+ 407
@@ -0,0 +1 @@
1
+ 909
@@ -0,0 +1 @@
1
+ 330
@@ -0,0 +1 @@
1
+ 891
@@ -0,0 +1 @@
1
+ 560
@@ -0,0 +1 @@
1
+ 426
@@ -0,0 +1 @@
1
+ 637
@@ -0,0 +1 @@
1
+ 921
@@ -0,0 +1 @@
1
+ 113
@@ -0,0 +1 @@
1
+ 374
@@ -0,0 +1 @@
1
+ 984
@@ -0,0 +1 @@
1
+ 267
@@ -0,0 +1 @@
1
+ 880
@@ -0,0 +1 @@
1
+ 396
@@ -0,0 +1 @@
1
+ 233
@@ -0,0 +1 @@
1
+ 502
@@ -0,0 +1 @@
1
+ 54
@@ -0,0 +1 @@
1
+ 25
@@ -0,0 +1 @@
1
+ 732
@@ -0,0 +1 @@
1
+ 522
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'fileutils'
3
+ require "#{File.dirname(__FILE__)}/../lib/unpack"
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec
7
+ end
@@ -0,0 +1,261 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper.rb')
2
+
3
+ # Preparing the file structure
4
+ def clear!
5
+ {'some_zip_files.zip' => 'zip_real', 'test_package.rar' => 'rar_real'}.each_pair do |taget|
6
+
7
+ # Removes old files in the test directory
8
+ Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/#{taget.last}/*")).each do |file|
9
+ FileUtils.rm(file) if Mimer.identify(file).text?
10
+ end
11
+
12
+ src = File.expand_path(File.dirname(__FILE__) + "/data/o_files/#{taget.first}")
13
+ dest = File.expand_path(File.dirname(__FILE__) + "/data/#{taget.last}/#{taget.first}")
14
+ FileUtils.copy_file(src, dest)
15
+ end
16
+
17
+ # Removes old files in the test directory
18
+ Dir.glob(File.expand_path(File.dirname(__FILE__) + "/data/movie_to/*")).each do |file|
19
+ FileUtils.rm(file) if Mimer.identify(file).text?
20
+ end
21
+ end
22
+
23
+ describe Unpack, "should work with the runner" do
24
+ before(:each) do
25
+ clear!
26
+ @path = File.expand_path('spec/data/rar_real')
27
+ @unpack = Unpack.runner!('spec/data/rar_real', remove: true, min_files: 0)
28
+ end
29
+
30
+ it "should unpack some files" do
31
+ clear!
32
+ files = %x{cd #{@path} && ls}.split(/\n/).count
33
+ Unpack.runner!('spec/data/rar_real', remove: true, min_files: 0)
34
+ %x{cd #{@path} && ls}.split(/\n/).count.should_not eq(files)
35
+ end
36
+
37
+ it "should have 1 directory" do
38
+ @unpack.count.should eq(1)
39
+ end
40
+
41
+ it "should have 5 new files" do
42
+ @unpack.first.should have(5).files
43
+ end
44
+
45
+ it "should only contain files that exists" do
46
+ @unpack.first.files.each do |file|
47
+ File.exists?(file).should be_true
48
+ end
49
+ end
50
+
51
+ it "should only contain an existsing directory" do
52
+ directory = @unpack.first.directory
53
+ Dir.exists?(directory).should be_true
54
+ end
55
+
56
+ it "should not remove old files when the remove param isn't present" do
57
+ clear!
58
+ Unpack.runner!('spec/data/rar_real', min_files: 0)
59
+ %x{cd #{@path} && ls}.should have(6).split(/\n/)
60
+ end
61
+
62
+ it "should remove old files if the remove param is present" do
63
+ clear!
64
+ Unpack.runner!('spec/data/rar_real', min_files: 0, remove: true)
65
+ %x{cd #{@path} && ls}.should have(5).split(/\n/)
66
+ end
67
+
68
+ it "should not find any files if the {min_files} param is very large" do
69
+ Unpack.runner!('spec/data/rar_real', min_files: 100).should be_empty
70
+ end
71
+
72
+ it "should return an Exception (not in production) if the path to Unpack.runner! does not exist" do
73
+ lambda {
74
+ Unpack.runner!('some/none/existing/path')
75
+ }.should raise_error(Exception)
76
+ end
77
+
78
+ it "should not return an exception without any arguments" do
79
+ lambda {
80
+ Unpack.runner!
81
+ }.should_not raise_error(Exception)
82
+ end
83
+
84
+ it "should allways return an array" do
85
+ Unpack.runner!('spec/data/rar_real', depth: 0).should be_instance_of(Array)
86
+ end
87
+ end
88
+
89
+ describe Unpack do
90
+ before(:each) do
91
+ clear!
92
+ @unpack = Unpack.new(directory: File.expand_path('spec/data/rar'))
93
+ @unpack.prepare!
94
+ end
95
+
96
+ it "should work" do
97
+ @unpack.should be_instance_of(Unpack)
98
+ end
99
+
100
+ it "should list all rar files in a directory" do
101
+ @unpack.should have_at_least(3).files
102
+ end
103
+
104
+ it "should only return rar-files" do
105
+ @unpack.files.each {|file| file.should match(/\.rar$/)}
106
+ end
107
+
108
+ it "should contain a absolut path to the file" do
109
+ @unpack.files.each {|file| file.should match(/^\//)}
110
+ end
111
+
112
+ it "should have some files with the name 'accessible'" do
113
+ @unpack.files.reject {|file| ! file.match(/\_accessible\_/) }.count.should > 0
114
+ end
115
+
116
+ it "should only contain files that exists" do
117
+ @unpack.files.each {|file| File.exists?(file).should be_true }
118
+ end
119
+
120
+ it "should not contain files that include a subtitle" do
121
+ @unpack.clean!
122
+ @unpack.files.each {|file| file.should_not match(/\_subtitle\_/) }
123
+ @unpack.should have_at_least(2).files
124
+ end
125
+
126
+ it "should not find files to deep" do
127
+ @unpack.clean!
128
+ @unpack.files.each {|file| file.should_not match(/\_not\_/) }
129
+ end
130
+
131
+ it "should only contain one rar file for each directory" do
132
+ @unpack.clean!
133
+ @unpack.should have(3).files
134
+ end
135
+
136
+ it "should not contain any strange files" do
137
+ @unpack.files.each {|file| file.should_not match(/\.strange$/)}
138
+ end
139
+
140
+ it "should have an executable unrar bin" do
141
+ File.executable_real?(@unpack.options[:absolute_path_to_unrar]).should be_true
142
+ end
143
+
144
+ it "should be possible to set and read options" do
145
+ @unpack = Unpack.new(directory: File.expand_path('spec/data/rar'), options: {debugger: true})
146
+ @unpack.options[:debugger].should be_true
147
+ end
148
+ end
149
+
150
+ describe Unpack, "should work with options" do
151
+ before(:each) do
152
+ clear!
153
+ end
154
+
155
+ it "should not return any files when min is set to 0" do
156
+ @unpack = Unpack.new(directory: File.expand_path('spec/data/rar'), options: {depth: 0})
157
+ @unpack.prepare!
158
+ @unpack.should have(0).files
159
+ end
160
+
161
+ it "should return subtitles rar files when min files is set to o" do
162
+ @unpack = Unpack.new(directory: File.expand_path('spec/data/rar'), options: {min_files: 0})
163
+ @unpack.prepare!
164
+ @unpack.clean!
165
+ @unpack.files.reject {|file| ! file.match(/\_subtitle\_/) }.count.should > 0
166
+ end
167
+
168
+ it "should access some really deep files" do
169
+ @unpack = Unpack.new(directory: File.expand_path('spec/data/rar'), options: {depth: 100})
170
+ @unpack.prepare!
171
+ @unpack.clean!
172
+ @unpack.files.reject {|file| ! file.match(/\_not\_/) }.count.should > 0
173
+ end
174
+ end
175
+
176
+ describe Unpack,"should work with zip files" do
177
+ before(:all) do
178
+ clear!
179
+ @path = File.expand_path('spec/data/zip_real')
180
+ @unpack = Unpack.new(directory: @path, options: {min_files: 1})
181
+ @unpack.prepare!
182
+ @unpack.clean!
183
+ end
184
+
185
+ it "should find some zip files" do
186
+ @unpack.should have_at_least(1).files
187
+ @unpack.files.reject {|file| ! file.match(/\.zip$/) }.count.should > 0
188
+ end
189
+
190
+ it "should be able to unpack zip files" do
191
+ @unpack.unpack!
192
+ %x{cd #{@path} && ls}.split(/\n/).reject {|file| ! file.match(/\_real\_/)}.count.should > 0
193
+ end
194
+
195
+ it "should return a list of new files" do
196
+ @unpack.should have(1).diff
197
+ end
198
+
199
+ it "should contain files" do
200
+ @unpack.diff.first.should have(5).files
201
+ end
202
+
203
+ it "should have and directory" do
204
+ @unpack.diff.first.directory.should_not be_nil
205
+ end
206
+
207
+ it "should only contain directories that is of the sort absolute" do
208
+ @unpack.diff.first.directory.should match(/^\//)
209
+ end
210
+
211
+ it "should contain valid files and directories, even if we call it 5 times" do
212
+ 5.times do
213
+ @unpack.diff.each do |work|
214
+ work.files.each do |file|
215
+ File.exists?(file).should be_true
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+
222
+ describe Unpack, "should work on real files" do
223
+ before(:each) do
224
+ clear!
225
+ @path = File.expand_path('spec/data/rar_real')
226
+ @unpack = Unpack.new(directory: @path, options: {min_files: 0})
227
+ @unpack.prepare!
228
+ @unpack.clean!
229
+ @unpack.unpack!
230
+ end
231
+
232
+ it "should the unpacked file when running the unpack! command" do
233
+ %x{cd #{@path} && ls}.split(/\n/).reject {|file| ! file.match(/\_real\_/)}.count.should > 0
234
+ end
235
+
236
+ it "should be able to remove archive files after unpack" do
237
+ files = %x{cd #{@path} && ls}.split(/\n/).count
238
+ @unpack.wipe!
239
+ %x{cd #{@path} && ls}.split(/\n/).count.should < files
240
+ end
241
+ end
242
+
243
+ describe Unpack, "should work with all kind of paths" do
244
+ it "should raise an exception if an invalid path is being used" do
245
+ lambda{
246
+ Unpack.new(directory: "/some/non/existing/dir")
247
+ }.should raise_error(Exception)
248
+ end
249
+
250
+ it "should work with a relative path" do
251
+ lambda{
252
+ Unpack.new(directory: "spec")
253
+ }.should_not raise_error(Exception)
254
+ end
255
+
256
+ it "should not work with an incorect relative path" do
257
+ lambda{
258
+ Unpack.new(directory: "spec/random")
259
+ }.should raise_error(Exception)
260
+ end
261
+ end