archive-tar-external 1.3.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/doc/tar_external.txt DELETED
@@ -1,110 +0,0 @@
1
- == Description
2
- A simple tar interface using external system calls.
3
-
4
- == Synopsis
5
- # Assuming we have three .txt files, t1.txt, t2.txt, t3.txt ...
6
- require 'archive/tar/external'
7
- include Archive
8
-
9
- t = Tar::External.new("myfile.tar")
10
-
11
- t.create_archive("*.txt")
12
- t.compress_archive("bzip2") # 'myfile.tar.bz2' now exists
13
-
14
- t.uncompress_archive("bunzip2")
15
-
16
- t.archive_name # "myfile.tar"
17
- t.archive_info # ["t1.txt","t2.txt","t3.txt"]
18
-
19
- t.add_to_archive("t4.txt","t5.txt")
20
- t.expand_archive
21
-
22
- == Constants
23
- VERSION
24
- Current version number of this library. This is a string.
25
-
26
- == Class Methods
27
- Archive::Tar::External.new(archive_name, pattern=nil, program=nil)
28
- Creates an instance of an Archive::Tar::External object. The +archive_name+ is
29
- the name of the tarball. While a '.tar' extension is recommended based on
30
- years of convention, it is not enforced.
31
-
32
- If +pattern+ is provided, then the Archive#create_archive method is called
33
- internally.
34
-
35
- If +program+ is provided, then the Archive#compress_archive method is
36
- called internally.
37
-
38
- Note that +archive_name+ name must be a String, or a TypeError is raised.
39
-
40
- Archive::Tar::External.expand_archive(archive_name, *files)
41
- Identical to the instance method of the same name, except that you must
42
- specify the +archive_name+, and the tar program is hard coded to 'tar xf'.
43
-
44
- Archive::Tar::External.uncompress_archive(archive_name, program='gunzip')
45
- Identical to the instance method of the same name, except that you must
46
- specify the +archive_name+ as the first argument.
47
-
48
- == Instance Methods
49
- Archive;:Tar#add(file1 [, file2, ...])
50
- Archive::Tar::External#add_to_archive(file1 [, file2, ...])
51
- Adds a list of files to the current archive. At least one file must be
52
- provided or a Tar::Error is raised.
53
-
54
- Archive::Tar::External#archive_info
55
- Archive::Tar::External#info
56
- Returns an array of file names that are included within the tarball.
57
-
58
- Archive::Tar::External#archive_name
59
- Returns the current archive name.
60
-
61
- Archive::Tar::External#archive_name=
62
- Sets the current archive name.
63
-
64
- Archive::Tar::External#compress(program="gzip")
65
- Archive::Tar::External#compress_archive(program="gzip")
66
- Compresses the tarball using the program you pass to this method. The
67
- default is "gzip".
68
-
69
- Note that any arguments you want to be passed along with the program can
70
- simply be included as part of the program, e.g. "gzip -f".
71
-
72
- Archive::Tar::External#create(file_pattern)
73
- Archive::Tar::External#create_archive(file_pattern, options = 'cf')
74
- Creates a new tarball, including those files which match 'file_pattern'
75
- using 'options', which are set to 'cf' (create file) by default.
76
-
77
- Archive::Tar::External#expand_archive(files=nil)
78
- Archive::Tar::External#extract_archive(files=nil)
79
- Expands the contents of the tarball. Note that this method does NOT delete
80
- the tarball.
81
-
82
- If file names are provided, then only those files are extracted.
83
-
84
- Archive::Tar::External#tar_program
85
- Returns the name of the tar program used. The default is "tar".
86
-
87
- Archive::Tar::External#tar_program=(program_name)
88
- Sets the name of the tar program to be used.
89
-
90
- Archive::Tar::External#uncompress(program="gunzip")
91
- Archive::Tar::External#uncompress_archive(program="gunzip")
92
- Uncompresses the tarball using the program you pass to this method. The
93
- default is "gunzip".
94
-
95
- As for compress_archive(), you can pass arguments along as part of the
96
- argument.
97
-
98
- Archive::Tar::External#update(files)
99
- Archive::Tar::External#update_archive(files)
100
- Updates the given +files+ in the archive, i.e they are added if they
101
- are not already in the archive or have been modified.
102
-
103
- == Exceptions
104
- Tar::Error
105
- Raised if something goes wrong during the execution of any methods that
106
- use the tar command internally.
107
-
108
- Tar::CompressError
109
- Raised if something goes wrong during the Tar#compress_archive or
110
- Tar#uncompress_archive methods.
@@ -1,208 +0,0 @@
1
- ###############################################################################
2
- # test_archive_tar_external.rb
3
- #
4
- # Test suite for the archive-tar-external library. This test case should be
5
- # run via the 'rake test' Rake task.
6
- ###############################################################################
7
- require 'archive/tar/external'
8
- require 'test-unit'
9
- require 'ptools'
10
- include Archive
11
-
12
- class TC_ArchiveTarExternal < Test::Unit::TestCase
13
- def self.startup
14
- Dir.chdir(File.dirname(File.expand_path(__FILE__)))
15
-
16
- @@tmp_file1 = 'temp1.txt'
17
- @@tmp_file2 = 'temp2.txt'
18
- @@tmp_file3 = 'temp3.txt'
19
-
20
- @@gtar_found = File.which('gtar')
21
- @@tar_found = File.which('tar')
22
- @@gzip_found = File.which('gzip')
23
- @@bzip2_found = File.which('bzip2')
24
-
25
- File.open(@@tmp_file1, 'w'){ |f| f.puts 'This is a temporary text file' }
26
- File.open(@@tmp_file2, 'w'){ |f| f.puts 'This is a temporary text file' }
27
- File.open(@@tmp_file3, 'w'){ |f| f.puts 'This is a temporary text file' }
28
- end
29
-
30
- def setup
31
- @tar = Tar::External.new('test.tar')
32
- @tar_name = 'test.tar'
33
- @pattern = '*.txt'
34
- @archive = 'temp.tar.gz'
35
- end
36
-
37
- def test_version
38
- assert_equal('1.3.2', Tar::External::VERSION)
39
- end
40
-
41
- def test_constructor
42
- assert_nothing_raised{ Tar::External.new(@tar_name) }
43
- end
44
-
45
- def test_constructor_with_extension
46
- assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt') }
47
- end
48
-
49
- def test_constructor_with_program
50
- omit_unless(@@gzip_found){ 'gzip program not found - skipping' }
51
- assert_nothing_raised{ Tar::External.new(@tar_name, '*.txt', 'gzip') }
52
- end
53
-
54
- def test_constructor_expected_errors
55
- assert_raise(ArgumentError){ Tar::External.new }
56
- end
57
-
58
- def test_tar_program
59
- assert_respond_to(@tar, :tar_program)
60
- assert_equal('tar', @tar.tar_program)
61
- end
62
-
63
- def test_archive_name
64
- assert_respond_to(@tar, :archive_name)
65
- assert_respond_to(@tar, :archive_name=)
66
-
67
- assert_equal('test.tar', @tar.archive_name)
68
- assert_nothing_raised{ @tar.archive_name }
69
- assert_nothing_raised{ @tar.archive_name = 'foo' }
70
- end
71
-
72
- def test_compressed_archive_name_get
73
- assert_respond_to(@tar, :compressed_archive_name)
74
- assert_nil(@tar.compressed_archive_name)
75
- end
76
-
77
- def test_compressed_archive_name_set
78
- assert_respond_to(@tar, :compressed_archive_name=)
79
- assert_nothing_raised{ @tar.compressed_archive_name = 'test.tar.gz' }
80
- assert_equal('test.tar.gz', @tar.compressed_archive_name)
81
- assert_equal('test.tar', @tar.archive_name)
82
-
83
- assert_nothing_raised{ @tar.compressed_archive_name = 'test.tgz' }
84
- assert_equal('test.tgz', @tar.compressed_archive_name)
85
- assert_equal('test.tar', @tar.archive_name)
86
- end
87
-
88
- test "create_archive basic functionality" do
89
- assert_respond_to(@tar, :create_archive)
90
- assert_nothing_raised{ @tar.create_archive(@pattern) }
91
- assert_true(File.exists?(@tar_name))
92
- end
93
-
94
- test "create_archive requires at least on argument" do
95
- assert_raises(ArgumentError){ @tar.create_archive }
96
- end
97
-
98
- test "create_archive raises an error if no files match the pattern" do
99
- assert_raises(Tar::Error){ @tar.create_archive('*.blah') }
100
- end
101
-
102
- test "create_archive accepts optional parameters" do
103
- assert_nothing_raised{ @tar.create_archive(@pattern, 'cfj') }
104
- end
105
-
106
- def test_create_alias
107
- assert_respond_to(@tar, :create)
108
- assert_true(Tar::External.instance_method(:create) == Tar::External.instance_method(:create_archive))
109
- end
110
-
111
- def test_compress_archive_basic
112
- assert_respond_to(@tar, :compress_archive)
113
- end
114
-
115
- def test_compress_alias
116
- assert_respond_to(@tar, :compress)
117
- assert_true(Tar::External.instance_method(:compress) == Tar::External.instance_method(:compress_archive))
118
- end
119
-
120
- def test_compress_archive_gzip
121
- assert_nothing_raised{ @tar.create_archive('*.txt') }
122
- assert_nothing_raised{ @tar.compress_archive }
123
-
124
- assert_equal('test.tar.gz', @tar.compressed_archive_name)
125
- assert_true(File.exists?('test.tar.gz'))
126
- end
127
-
128
- def test_compress_archive_bzip2
129
- assert_nothing_raised{ @tar.create_archive('*.txt') }
130
- assert_nothing_raised{ @tar.compress_archive('bzip2') }
131
- assert_true(File.exists?('test.tar.bz2'))
132
- end
133
-
134
- def test_uncompress_archive
135
- assert_respond_to(@tar, :uncompress_archive)
136
- assert_nothing_raised{ @tar.create_archive('*.txt') }
137
- assert_nothing_raised{ @tar.compress_archive }
138
- assert_nothing_raised{ @tar.uncompress_archive }
139
- assert_false(File.exists?('test.tar.gz'))
140
- end
141
-
142
- def test_uncompress_archive_class_method
143
- assert_respond_to(Tar::External, :uncompress_archive)
144
- end
145
-
146
- def test_uncompress_alias
147
- assert_respond_to(Tar::External, :uncompress)
148
- assert_true(Tar::External.method(:uncompress) == Tar::External.method(:uncompress_archive))
149
- end
150
-
151
- def test_archive_info
152
- assert_respond_to(@tar, :archive_info)
153
- assert_nothing_raised{ @tar.create_archive('*.txt') }
154
- assert_equal(['temp1.txt','temp2.txt','temp3.txt'], @tar.archive_info)
155
- end
156
-
157
- def test_add_to_archive
158
- assert_respond_to(@tar,:add_to_archive)
159
- assert_nothing_raised{ @tar.create_archive('temp1.txt') }
160
- assert_nothing_raised{ @tar.add_to_archive('temp2.txt') }
161
- assert_nothing_raised{ @tar.add_to_archive('temp2.txt','temp3.txt') }
162
- end
163
-
164
- def test_update_archive
165
- assert_respond_to(@tar, :update_archive)
166
- assert_nothing_raised{ @tar.create_archive('*.txt') }
167
- assert_nothing_raised{ @tar.update_archive('temp2.txt') }
168
- end
169
-
170
- def test_extract_archive_basic
171
- assert_respond_to(@tar, :extract_archive)
172
- end
173
-
174
- def test_extract_archive_aliases
175
- assert_true(Tar::External.instance_method(:extract_archive) == Tar::External.instance_method(:expand_archive))
176
- assert_true(Tar::External.instance_method(:extract) == Tar::External.instance_method(:expand_archive))
177
- assert_true(Tar::External.instance_method(:expand) == Tar::External.instance_method(:expand_archive))
178
- end
179
-
180
- def test_extract_archive_advanced
181
- omit_unless(RbConfig::CONFIG['host_os'] =~ /sunos|solaris/){
182
- assert_nothing_raised{ @tar.tar_program = @@gtar }
183
- }
184
- assert_nothing_raised{ @tar.create('*.txt') }
185
- assert_raises(Tar::Error){ @tar.expand('blah.txt') }
186
-
187
- assert_nothing_raised{ @tar.extract_archive }
188
- assert_nothing_raised{ @tar.extract_archive('temp2.txt') }
189
- end
190
-
191
- def teardown
192
- @tar = nil
193
- File.delete('test.tar') if File.exists?('test.tar')
194
- File.delete('test.tar.gz') if File.exists?('test.tar.gz')
195
- File.delete('test.tar.bz2') if File.exists?('test.tar.bz2')
196
- File.delete('test.tar.zip') if File.exists?('test.tar.zip')
197
- end
198
-
199
- def self.shutdown
200
- @@tar_foudn = nil
201
- @@gzip_found = nil
202
- @@bzip2_found = nil
203
-
204
- File.delete(@@tmp_file1) if File.exists?(@@tmp_file1)
205
- File.delete(@@tmp_file2) if File.exists?(@@tmp_file2)
206
- File.delete(@@tmp_file3) if File.exists?(@@tmp_file3)
207
- end
208
- end