minitar 1.0.1 → 1.1.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +285 -0
  3. data/CONTRIBUTING.md +273 -0
  4. data/CONTRIBUTORS.md +27 -0
  5. data/LICENCE.md +39 -0
  6. data/Manifest.txt +29 -6
  7. data/README.md +70 -0
  8. data/Rakefile +74 -19
  9. data/SECURITY.md +64 -0
  10. data/docs/ruby.txt +3 -3
  11. data/lib/minitar/input.rb +69 -56
  12. data/lib/minitar/output.rb +34 -22
  13. data/lib/minitar/pax_header.rb +111 -0
  14. data/lib/minitar/posix_header.rb +96 -57
  15. data/lib/minitar/reader.rb +65 -70
  16. data/lib/minitar/version.rb +5 -0
  17. data/lib/minitar/writer.rb +50 -88
  18. data/lib/minitar.rb +60 -64
  19. data/licenses/bsdl.txt +20 -0
  20. data/licenses/dco.txt +34 -0
  21. data/licenses/ruby.txt +52 -0
  22. data/test/fixtures/issue_46.tar.gz +0 -0
  23. data/test/fixtures/issue_62.tar.gz +0 -0
  24. data/test/fixtures/tar_input.tgz +0 -0
  25. data/test/fixtures/test_input_non_strict_octal.tgz +0 -0
  26. data/test/fixtures/test_input_relative.tgz +0 -0
  27. data/test/fixtures/test_input_space_octal.tgz +0 -0
  28. data/test/fixtures/test_minitar.tar.gz +0 -0
  29. data/test/minitest_helper.rb +12 -1
  30. data/test/support/minitar_test_helpers/fixtures.rb +38 -0
  31. data/test/support/minitar_test_helpers/header.rb +130 -0
  32. data/test/support/minitar_test_helpers/tarball.rb +324 -0
  33. data/test/support/minitar_test_helpers.rb +36 -0
  34. data/test/test_filename_boundary_conditions.rb +74 -0
  35. data/test/test_gnu_tar_compatibility.rb +92 -0
  36. data/test/test_integration_pack_unpack_cycle.rb +38 -0
  37. data/test/test_issue_46.rb +5 -23
  38. data/test/test_issue_62.rb +50 -0
  39. data/test/test_minitar.rb +168 -39
  40. data/test/test_pax_header.rb +104 -0
  41. data/test/test_pax_support.rb +66 -0
  42. data/test/test_tar_header.rb +289 -75
  43. data/test/test_tar_input.rb +14 -61
  44. data/test/test_tar_output.rb +7 -9
  45. data/test/test_tar_reader.rb +17 -18
  46. data/test/test_tar_writer.rb +105 -126
  47. metadata +95 -89
  48. data/Contributing.md +0 -94
  49. data/History.md +0 -223
  50. data/Licence.md +0 -15
  51. data/README.rdoc +0 -92
  52. data/test/support/tar_test_helpers.rb +0 -134
  53. /data/{Code-of-Conduct.md → CODE_OF_CONDUCT.md} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34543cdcb4d355d895541547346230ea36725bc467a47a4ce73ed1b7a9f37290
4
- data.tar.gz: 599df4d6171a30b7dd1cc74290eb6a331a7760487a6d82a9bceeaea1d19fa6cf
3
+ metadata.gz: 59638d7516e33ff6d61b73b96aaa0b17446606dfebaff5c04ba2f4cb29db842e
4
+ data.tar.gz: b90a67f815f2f4ee38f5b4a0050d6bc2ef52794b3da80e767fee4a66c57ed2c3
5
5
  SHA512:
6
- metadata.gz: 91c839b8c740a57eaa4066a26843306e0d64217428a47491fd91599fcbfae2e65e20f97214f524df41960b7c43b09427ee25dfa5d6a11ab876762c81eab5be4d
7
- data.tar.gz: 494b4c63e3f118fde75cf3e1ef7c0de7434cbb219484a99bb7d4e15d7c606dbb2445d10ef71843f894d6de6a9f785559dd767829948a234aaacd3a703cd515a2
6
+ metadata.gz: 5b3f09d060b05dee333e3e2652b0b36e9533b3be9b9dbc94cb25948e12905d6518678774ab74a770723e21ebd583ee2bbb2a5d5b75ef38884632dc1e71a4ca84
7
+ data.tar.gz: 95354454f621aabe1d5c20615ac48a5b4f92ab27c35af1cf296afca5b3516369e12c54ac01175fd472715d7fdf509f8c7ed358b9e84ad672d0d9fb1407a195d8
data/CHANGELOG.md ADDED
@@ -0,0 +1,285 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0 / 2025-09-07
4
+
5
+ - Enhancements:
6
+
7
+ - Support large file size encoded in base-256 encoding which is a GNU tar
8
+ extension [#121][pull-121].
9
+
10
+ - Support large file size encoded in PAX extension header. [#121][pull-121].
11
+
12
+ - Bug fix:
13
+
14
+ - Resolved [#62][issue-62]. The initial solution was developed with the
15
+ assistance of Claude Sonnet 4 via Kiro, but nearly every line of the
16
+ solution and tests were rewritten as part of a comprehensive review of all
17
+ tests.
18
+
19
+ - Breaking Change:
20
+
21
+ - Removed `Minitar::PosixHeader.new_from_stream` which should have been
22
+ removed with 1.0.0 and has been deprecated for a decade or so.
23
+
24
+ - Governance:
25
+
26
+ Changes described below are effective 2024-12-31.
27
+
28
+ - Update gem management details to use markdown files for everything, enabled
29
+ in part by [flavorjones/hoe-markdown][hoe-markdown]. Several files were
30
+ renamed to be more consistent with standard practices.
31
+
32
+ - Updated security notes with an [age][age] public key rather than pointing to
33
+ Keybase.io and a PGP public key which I no longer use. The use of the
34
+ [Tidelift security contact][tidelift] is recommended over direct disclosure.
35
+
36
+ Changes described below are effective 2025-08-04.
37
+
38
+ - Contributions to minitar now require a DCO certification.
39
+
40
+ ## 1.0.2 / 2024-08-23
41
+
42
+ - Bug fix:
43
+
44
+ - Minitar 1.0.1 was released with an unchanged gemspec. Reported by Debashish
45
+ Biswas in [#65][issue-65].
46
+
47
+ ## 1.0.1 / 2024-08-08
48
+
49
+ - Bug fix:
50
+
51
+ - Resolve a constant lookup issue. The accepted fix has been provided by Aram
52
+ Price in [#58][issue-58].
53
+
54
+ ## 1.0.0 / 2024-08-07
55
+
56
+ - Breaking Changes:
57
+
58
+ - Minimum Ruby version is 3.1.
59
+
60
+ - The `Archive::Tar::Minitar` namespace has been completely removed and
61
+ `Minitar` is a class instead of a module.
62
+
63
+ - Enhancements:
64
+
65
+ - Added `Minitar.pack_as_file`, originally proposed by John Prince back in
66
+ 2011 [#7][issue-07].
67
+
68
+ ## 0.12.1 / 2024-08-21
69
+
70
+ - Reverted adbbb9b596 to restore compatibility with Ruby < 2.0. Resolves
71
+ [#63][issue-63] reported by Robert Schulze.
72
+
73
+ ## 0.12 / 2024-08-06
74
+
75
+ - Properly handle very long GNU filenames, resolving [#46][issue-46].
76
+ - Handle very long GNU filenames that are 512 or more bytes, resolving
77
+ [#45][issue-45]. Originally implemented in [#47][pull-47] by Vijay, but
78
+ accidentally closed.
79
+
80
+ ## 0.11 / 2022-12-31
81
+
82
+ - symlink support is complete. Merged as PR [#42][pull-42], rebased and built on
83
+ top of PR [#12][pull-12] by fetep.
84
+
85
+ - kymmt90 fixed a documentation error on `Minitar.pack` in PR [#43][pull-43].
86
+
87
+ - This version is a soft-deprecation of all versions before Ruby 2.7, as they
88
+ will no longer be tested in CI.
89
+
90
+ ## 0.10 / 2022-03-26
91
+
92
+ - nevesenin fixed an issue with long filename handling. Merged as PR
93
+ [#40][pull-40].
94
+
95
+ ## 0.9 / 2019-09-04
96
+
97
+ - jtappa added the ability to skip fsync with a new option to `Minitar.unpack`
98
+ and `Minitar::Input#extract_entry`. Provide `:fsync => false` as the last
99
+ parameter to enable. Merged from a modified version of PR [#37][pull-37].
100
+
101
+ ## 0.8 / 2019-01-05
102
+
103
+ - [@inkstak](https://github.com/inkstak) resolved an issue introduced in the fix
104
+ for [#31][issue-31] by allowing spaces to be considered valid characters in
105
+ strict octal handling. Octal conversion ignores leading spaces. Merged from a
106
+ slightly modified version of PR [#35][pull-35].
107
+
108
+ - [@dearblue](https://github.com/dearblue) contributed PR [#32][pull-32]
109
+ providing an explicit call to #bytesize for strings that include multibyte
110
+ characters. The PR has been modified to be compatible with older versions of
111
+ Ruby and extend tests.
112
+
113
+ - Akinori MUSHA (knu) contributed PR [#36][pull-36] that treats certain badly
114
+ encoded regular files (with names ending in `/`) as if they were directories
115
+ on decode.
116
+
117
+ ## 0.7 / 2018-02-19
118
+
119
+ - Fixed issue [#28][issue-28] with a modified version of PR [#29][pull-29]
120
+ covering the security policy and position for `Minitar`. Thanks so much to
121
+ [@ooooooo-q](https://github.com/ooooooo-q) for the report and an initial
122
+ patch. Additional information was added as [#30][issue-30].
123
+
124
+ - [@dearblue](https://github.com/dearblue) contributed PR [#33][pull-33]
125
+ providing a fix for `Minitar::Reader` when the IO-like object does not have a
126
+ `#pos` method.
127
+
128
+ - Kevin McDermott contributed PR [#34][pull-34] so that an InvalidTarStream is
129
+ raised if the tar header is not valid, preventing incorrect streaming of files
130
+ from a non-tarfile. This is a minor breaking change, so the version has been
131
+ bumped accordingly.
132
+
133
+ - Kazuyoshi Kato contributed PR [#26][pull-26] providing support for the GNU tar
134
+ long filename extension.
135
+
136
+ - Addressed a potential DOS with negative size fields in tar headers
137
+ ([#31][issue-31]). This has been handled in two ways: the size field in a tar
138
+ header is interpreted as a strict octal value and the `Minitar` reader will
139
+ raise an InvalidTarStream if the size ends up being negative anyway.
140
+
141
+ ## 0.6.1 / 2017-02-07
142
+
143
+ - Fixed issue [#24][issue-24] where streams were being improperly closed
144
+ immediately on open unless there was a block provided.
145
+
146
+ - Hopefully fixes issue [#23][issue-23] by releasing archive-tar-minitar after
147
+ minitar-cli is available.
148
+
149
+ ## 0.6 / 2017-02-07
150
+
151
+ - Breaking Changes:
152
+
153
+ - Extracted `bin/minitar` into a new gem, `minitar-cli`. No, I am _not_ going
154
+ to bump the major version for this. As far as I can tell, few people use the
155
+ command-line utility anyway. (Installing `archive-tar-minitar` will install
156
+ both `minitar` and `minitar-cli`, at least until version 1.0.)
157
+
158
+ - `Minitar` extraction before 0.6 traverses directories if the tarball
159
+ includes a relative directory reference, as reported in [#16][issue-16] by
160
+ [@ecneladis](https://github.com/ecneladis). This has been disallowed
161
+ entirely and will throw a `SecureRelativePathError` when found.
162
+ Additionally, if the final destination of an entry is an already-existing
163
+ symbolic link, the existing symbolic link will be removed and the file will
164
+ be written correctly (on platforms that support symbolic links).
165
+
166
+ - Enhancements:
167
+
168
+ - Licence change. After speaking with Mauricio Fernández, we have changed the
169
+ licensing of this library to Ruby and Simplified BSD and have dropped the
170
+ GNU GPL license. This takes effect from the 0.6 release.
171
+ - Printing a deprecation warning for including Archive::Tar to put `Minitar`
172
+ in the top-level namespace.
173
+ - Printing a deprecation warning for including `Archive::Tar::Minitar` into a
174
+ class (`Minitar` will be a class for version 1.0).
175
+ - Moved `Archive::Tar::PosixHeader` to `Archive::Tar::Minitar::PosixHeader`
176
+ with a deprecation warning. Do not depend on
177
+ `Archive::Tar::Minitar::PosixHeader`, as it will be moving to
178
+ `::Minitar::PosixHeader` in a future release.
179
+ - Added an alias, `::Minitar`, for `Archive::Tar::Minitar`, opted in with
180
+ `require 'minitar'`. In future releases, this alias will be enabled by
181
+ default, and the `Archive::Tar` namespace will be removed entirely for
182
+ version 1.0.
183
+ - Modified the handling of `mtime` in `PosixHeader` to do an integer
184
+ conversion (`#to_i`) so that a Time object can be used instead of the
185
+ integer value of the time object.
186
+ - `Writer::RestrictedStream` was renamed to `Writer::WriteOnlyStream` for
187
+ clarity. No alias or deprecation warning was provided for this as it is an
188
+ internal implementation detail.
189
+ - `Writer::BoundedStream` was renamed to `Writer::BoundedWriteStream` for
190
+ clarity. A deprecation warning is provided on first use because a
191
+ BoundedWriteStream may raise a `BoundedWriteStream::FileOverflow` exception.
192
+ - `Writer::BoundedWriteStream::FileOverflow` has been renamed to
193
+ `Writer::WriteBoundaryOverflow` and inherits from `StandardError` instead of
194
+ `RuntimeError`. Note that for Ruby 2.0 or higher, an error will be raised
195
+ when specifying `Writer::BoundedWriteStream::FileOverflow` because
196
+ `Writer::BoundedWriteStream` has been declared a private constant.
197
+ - Modified `Writer#add_file_simple` to accept the data for a file in
198
+ `opts[:data]`. When `opts[:data]` is provided, a stream block must not be
199
+ provided. Improved the documentation for this method.
200
+ - Modified `Writer#add_file` to accept `opts[:data]` and transparently call
201
+ `Writer#add_file_simple` in this case.
202
+ - Methods that require blocks are no longer required, so the
203
+ `Archive::Tar::Minitar::BlockRequired` exception has been removed with a
204
+ warning (this may not work on Ruby 1.8).
205
+ - Dramatically reduced the number of strings created when creating a POSIX
206
+ tarball header.
207
+ - Added a helper, `Input.each_entry` that iterates over each entry in an
208
+ opened entry object.
209
+
210
+ - Bugs:
211
+
212
+ - Fix [#2][issue-02] to handle IO streams that are not seekable, such as
213
+ pipes, `STDIN`, or `STDOUT`.
214
+ - Fix [#3][issue-03] to make the test timezone resilient.
215
+ - Fix [#4][issue-04] for supporting the reading of tar files with filenames in
216
+ the GNU long filename extension format. Ported from
217
+ [@atoulme](https://github.com/atoulme)’s fork, originally provided by Curtis
218
+ Sampson.
219
+ - Fix [#6][issue-06] by making it raise the correct error for a long filename
220
+ with no path components.
221
+ - Fix [#13][issue-13] provided by [@fetep](https://github.com/fetep) fixes an
222
+ off-by-one error on filename splitting.
223
+ - Fix [#14][issue-14] provided by [@kzys](https://github.com/kzys) should fix
224
+ Windows detection issues.
225
+ - Fix [#16][issue-16] as specified above.
226
+ - Fix an issue where `Minitar.pack` would not include Unix hidden files when
227
+ creating a tarball.
228
+
229
+ - Development:
230
+
231
+ - Modernized minitar tooling around Hoe.
232
+ - Added travis and coveralls.
233
+
234
+ ## 0.5.2 / 2008-02-26
235
+
236
+ - Bugs:
237
+ - Fixed a Ruby 1.9 compatibility error.
238
+
239
+ ## 0.5.1 / 2004-09-27
240
+
241
+ - Bugs:
242
+ - Fixed a variable name error.
243
+
244
+ ## 0.5.0
245
+
246
+ - Initial release. Does files and directories. Command does create, extract, and
247
+ list.
248
+
249
+ [age]: https://github.com/FiloSottile/age
250
+ [hoe-halostatue]: https://github.com/halostatue/hoe-halostatue
251
+ [hoe-markdown]: https://github.com/flavorjones/hoe-markdown
252
+ [issue-02]: https://github.com/halostatue/minitar/issues/2
253
+ [issue-03]: https://github.com/halostatue/minitar/issues/3
254
+ [issue-04]: https://github.com/halostatue/minitar/issues/4
255
+ [issue-06]: https://github.com/halostatue/minitar/issues/6
256
+ [issue-07]: https://github.com/halostatue/minitar/issues/7
257
+ [issue-13]: https://github.com/halostatue/minitar/issues/13
258
+ [issue-14]: https://github.com/halostatue/minitar/issues/14
259
+ [issue-16]: https://github.com/halostatue/minitar/issues/16
260
+ [issue-23]: https://github.com/halostatue/minitar/issues/23
261
+ [issue-24]: https://github.com/halostatue/minitar/issues/24
262
+ [issue-28]: https://github.com/halostatue/minitar/issues/28
263
+ [issue-30]: https://github.com/halostatue/minitar/issues/30
264
+ [issue-31]: https://github.com/halostatue/minitar/issues/31
265
+ [issue-45]: https://github.com/halostatue/minitar/issues/45
266
+ [issue-46]: https://github.com/halostatue/minitar/issues/46
267
+ [issue-58]: https://github.com/halostatue/minitar/issues/58
268
+ [issue-62]: https://github.com/halostatue/minitar/issues/62
269
+ [issue-63]: https://github.com/halostatue/minitar/issues/63
270
+ [issue-65]: https://github.com/halostatue/minitar/issues/65
271
+ [pull-12]: https://github.com/halostatue/minitar/pull/12
272
+ [pull-26]: https://github.com/halostatue/minitar/pull/26
273
+ [pull-29]: https://github.com/halostatue/minitar/pull/29
274
+ [pull-32]: https://github.com/halostatue/minitar/pull/32
275
+ [pull-33]: https://github.com/halostatue/minitar/pull/33
276
+ [pull-34]: https://github.com/halostatue/minitar/pull/34
277
+ [pull-35]: https://github.com/halostatue/minitar/pull/35
278
+ [pull-36]: https://github.com/halostatue/minitar/pull/36
279
+ [pull-37]: https://github.com/halostatue/minitar/pull/37
280
+ [pull-40]: https://github.com/halostatue/minitar/pull/40
281
+ [pull-42]: https://github.com/halostatue/minitar/pull/42
282
+ [pull-43]: https://github.com/halostatue/minitar/pull/43
283
+ [pull-47]: https://github.com/halostatue/minitar/pull/47
284
+ [pull-121]: https://github.com/halostatue/minitar/pull/121
285
+ [tidelift]: https://tidelift.com/security
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,273 @@
1
+ # Contributing
2
+
3
+ Contribution to minitar is encouraged: bug reports, feature requests, or code
4
+ contributions. There are a few DOs and DON'Ts that should be followed:
5
+
6
+ - DO:
7
+
8
+ - Keep the coding style that already exists for any updated Ruby code (support
9
+ or otherwise). I use [Standard Ruby][standardrb] for linting and formatting.
10
+
11
+ - Use thoughtfully-named topic branches for contributions. Rebase your commits
12
+ into logical chunks as necessary.
13
+
14
+ - Use [quality commit messages][qcm] for each commit (minitar uses a rebase
15
+ merge strategy). Ensure that each commit includes the required Developer
16
+ Certificate of Origin [sign-off][sign-off].
17
+
18
+ - Add your name or GitHub handle to `CONTRIBUTORS.md` and a record in the
19
+ `CHANGELOG.md` as a separate commit from your main change. (Follow the style
20
+ in the `CHANGELOG.md` and provide a link to your PR.)
21
+
22
+ - Add or update tests as appropriate for your change. The test suite is
23
+ written with [minitest][minitest].
24
+
25
+ - Add or update documentation as appropriate for your change. The
26
+ documentation is RDoc; mime-types does not use extensions that may be
27
+ present in alternative documentation generators.
28
+
29
+ - DO NOT:
30
+
31
+ - Modify `VERSION` in `lib/minitar/version.rb`. When your patch is accepted
32
+ and a release is made, the version will be updated at that point.
33
+
34
+ - Modify `minitar.gemspec`; it is a generated file. (You _may_ use
35
+ `rake gemspec` to regenerate it if your change involves metadata related to
36
+ gem itself).
37
+
38
+ - Modify the `Gemfile`.
39
+
40
+ ## LLM-Generated Contribution Policy
41
+
42
+ minitar-cli accepts only issues or pull requests that are well understood by the
43
+ submitter and that, especially for pull requests, the developer can attest to
44
+ the [Developer Certificate of Origin][dco] for each pull request (see
45
+ [LICENCE](LICENCE.md)).
46
+
47
+ If LLM assistance is used in writing pull requests, this must be documented in
48
+ the commit message and pull request. If there is evidence of LLM assistance
49
+ without such declaration, the pull request **will be declined**.
50
+
51
+ Any contribution (bug, feature request, or pull request) that uses unreviewed
52
+ LLM output will be rejected.
53
+
54
+ For an example of how this should be done, see [#151][pr-151] and its
55
+ [associated commits][pr-151-commits].
56
+
57
+ ## Test
58
+
59
+ minitar uses Ryan Davis's [Hoe][Hoe] to manage the release process, and it adds
60
+ a number of rake tasks. You will mostly be interested in `rake`, which runs
61
+ tests in the same way that `rake test` does.
62
+
63
+ To assist with the installation of the development dependencies for minitar, I
64
+ have provided the simplest possible Gemfile pointing to the (generated)
65
+ `minitar.gemspec` file. This will permit you to use `bundle install` to install
66
+ the development dependencies.
67
+
68
+ You can run tests with code coverage analysis by running `rake coverage`.
69
+
70
+ ### Test Helpers
71
+
72
+ Minitar includes a number of custom test assertions, constants, and test utility
73
+ methods that are useful for writing tests. These are maintained through modules
74
+ defined in `test/support`.
75
+
76
+ #### Fixture Utilities
77
+
78
+ Minitar uses fixture tarballs in various tests, referenced by their base name
79
+ (`test/fixtures/tar_input.tar.gz` becomes `tar_input`, etc.). There are two
80
+ utility methods:
81
+
82
+ - `Fixture(name)`: This returns the `Pathname` object for the full path of the
83
+ named fixture tarball or `nil` if the named fixture does not exist.
84
+
85
+ - `open_fixture(name)`: This retrieves the named fixture and opens it. If the
86
+ fixture ends with `.gz` or `.tgz`, it will be opened with a
87
+ `Zlib::GZipReader`. A block may be provided to ensure that the fixture is
88
+ automatically closed.
89
+
90
+ #### Header Assertions and Utilities
91
+
92
+ Tar headers need to be built and compared in an exacting way, even for tests.
93
+
94
+ There are two assertions:
95
+
96
+ - `assert_headers_equal(expected, actual)`: This compares headers by field order
97
+ verifying that each field in `actual` is supposed to match the corresponding
98
+ field in `expected`.
99
+
100
+ `expected` must be a string representation of the expected header and this
101
+ assertion calls `#to_s` on the `actual` value so that both `PosixHeader` and
102
+ `PaxHeader` instances are converted to string representations for comparison.
103
+
104
+ - `assert_modes_equal(expected, actual, filename)`: This compares the expected
105
+ octal mode string of `expected` against `actual` for a given `filename`. The
106
+ modes must be integer values. This assertion is skipped on Windows.
107
+
108
+ There are several other helper methods available for working with headers:
109
+
110
+ - `build_tar_file_header(name, prefix, mode, length)`: This builds a header for
111
+ a file `prefix/name` with `mode` and `length` bytes. `name` is limited to 100
112
+ bytes and `prefix` is limited to 155 bytes.
113
+
114
+ - `build_tar_dir_header(name, prefix, mode)`: This builds a header for a
115
+ directory `prefix/name` with `mode`. `name` is limited to 100 bytes and
116
+ `prefix` is limited to 155 bytes.
117
+
118
+ - `build_tar_symlink_header(name, prefix, mode, target)`: This builds a header
119
+ for a symbolic link of `prefix/name` to `target` where the symbolic link has
120
+ `mode`. `name` is limited to 100 bytes and `prefix` is limited to 155 bytes.
121
+
122
+ - `build_tar_pax_header(name, prefix, bytes)`: This builds a header block for a
123
+ PAX extension at `name/prefix` with `content_size` bytes.
124
+
125
+ - `build_header(type, name, prefix, size, mode, link = "")`: This builds an
126
+ otherwise unspecified header type. If you find yourself using this, it is
127
+ recommended to add a new `build_*_header` helper method.
128
+
129
+ #### Tarball Helpers
130
+
131
+ Minitar has several complex assertions and utilities to work with both in-memory
132
+ and on-disk tarballs. These work using two concepts, file hashes (`file_hash`)
133
+ and workspaces (`workspace`).
134
+
135
+ ##### File Hashes (`file_hash`)
136
+
137
+ Many of these consume or produce a `file_hash`, which is a hash of
138
+ `{filename => content}` where the tarball will be produced with such that each
139
+ entry in the `file_hash` becomes a file named `filename` with the data
140
+ `content`.
141
+
142
+ As an example, `Minitar::TestHelpers` has a `MIXED_FILENAME_SCENARIOS` constant
143
+ that is a `file_hash`:
144
+
145
+ ```ruby
146
+ MIXED_FILENAME_SCENARIOS = {
147
+ "short.txt" => "short content",
148
+ "medium_length_filename_under_100_chars.txt" => "medium content",
149
+ "dir1/medium_filename.js" => "medium nested content",
150
+ "#{"x" * 120}.txt" => "long content",
151
+ "nested/dir/#{"y" * 110}.css" => "long nested content"
152
+ }.freeze
153
+ ```
154
+
155
+ This will produce a tarball that looks like:
156
+
157
+ ```
158
+ short.txt
159
+ medium_length_filename_under_100_chars.txt
160
+ dir1/medium_filename.js
161
+ x[118 more 'x' characters...]x
162
+ nested/dir/y[108 more y' characters...]y.css
163
+ ```
164
+
165
+ Each file will contain the text as the content.
166
+
167
+ If the `content` is `nil`, this will be ignored for in-memory tarballs, but will
168
+ be created as empty directory entries for on-disk tarballs.
169
+
170
+ ##### Workspace (`workspace`)
171
+
172
+ A workspace is a temporary directory used for on-disk tests. It is created with
173
+ the `workspace` utility method (see below) and must be passed a block where all
174
+ setup and tests will be run.
175
+
176
+ At most one `workspace` may be used per test method.
177
+
178
+ ##### Assertions
179
+
180
+ There are five assertions:
181
+
182
+ - `assert_tar_structure_preserved(original_files, extracted_files)`: This is
183
+ used primarily with string tarballs. Given two `file_hash`es representing
184
+ tarball contents (the original files passed to `create_tar_string` and the
185
+ extracted files returned from `extract_tar_string`), it ensures that all files
186
+ from the original contents are present and that no additional files have been
187
+ added in the process.
188
+
189
+ - `assert_files_extracted_in_workspace`: Can only be run in a `workspace` and
190
+ the test tarball must have been both created and extracted. This ensures that
191
+ all of the files and/or directories expected have been extracted and that the
192
+ contents of files match. File modes are ignored for this assertion.
193
+
194
+ - `refute_file_path_duplication_in_workspace`: Can only be run in a `workspace`
195
+ and the test tarball must have been both created and extracted. This is used
196
+ to prevent regression of [#62][issue-62] with explicit file tests. This only
197
+ needs to be called after unpacking with Minitar methods.
198
+
199
+ - `assert_extracted_files_match_source_files_in_workspace`: Can only be run in a
200
+ `workspace` and the test tarball must have been both created and extracted.
201
+ This ensures that there are no files missing or added in the `target`
202
+ directory that should are not also be in the `source` directory. This does no
203
+ contents comparison.
204
+
205
+ - `assert_file_modes_match_in_workspace`: Can only be run in a `workspace` and
206
+ the test tarball must have been both created and extracted. This ensures that
207
+ all files have the same modes between source and target. This is skipped on
208
+ Windows.
209
+
210
+ ##### In-Memory Tarball Utilities
211
+
212
+ - `create_tar_string`: Given a `file_hash`, this creates a string containing the
213
+ output of `Minitar::Output.open` and `Minitar.pack_as_file`.
214
+
215
+ - `extract_tar_string`: Given the string output of `create_tar_string` (or any
216
+ uncompressed tarball string), uses `Minitar::Input.open` to read the files
217
+ into a hash of `{filename => content}`.
218
+
219
+ - `roundtrip_tar_string`: calls `create_tar_string` on a `file_hash` and
220
+ immediately calls `extract_tar_string`, returning a processed `file_hash`.
221
+
222
+ ##### On-Disk Workspace Tarball Utilities
223
+
224
+ - `workspace`: Prepares a temporary directory for working with tarballs on disk
225
+ inside the block that must be provided. If given a hash of files, calls
226
+ `prepare_files`. The workspace directory will be removed after the block
227
+ finishes executing.
228
+
229
+ A workspace has a `source` directory, a `target` directory`, and the`tarball`
230
+ which will be created from the prepared files.
231
+
232
+ All other utility methods _must_ be run inside of a `workspace` block.
233
+
234
+ - `prepare_workspace`: creates a file structure in the workspace source
235
+ directory given the `{filename => content}` hash. For on-disk file structures,
236
+ `{directory_name => nil}` can be used to create empty directories. Directory
237
+ names will be created automatically for nested filenames.
238
+
239
+ - `gnu_tar_create_in_workspace`, `gnu_tar_extract_in_workspace`, and
240
+ `gnu_tar_list_in_workspace` work with the workspace tarball using GNU tar
241
+ (either `tar` or `gtar`). GNU tar tests will be skipped if GNU tar is not
242
+ available.
243
+
244
+ - `minitar_pack_in_workspace`, `minitar_unpack_in_workspace` use `Minitar.pack`
245
+ and `Minitar.unpack`, respectively, to work with the workspace tarball.
246
+
247
+ - `minitar_writer_create_in_workspace` uses `Minitar::Writer` to create the
248
+ workspace tarball.
249
+
250
+ ## Workflow
251
+
252
+ Here's the most direct way to get your work merged into the project:
253
+
254
+ - Fork the project.
255
+ - Clone your fork (`git clone git://github.com/<username>/minitar.git`).
256
+ - Create a topic branch to contain your change
257
+ (`git checkout -b my_awesome_feature`).
258
+ - Hack away, add tests. Not necessarily in that order.
259
+ - Make sure everything still passes by running `rake`.
260
+ - If necessary, rebase your commits into logical chunks, without errors.
261
+ - Push the branch up (`git push origin my_awesome_feature`).
262
+ - Create a pull request against halostatue/minitar and describe what your change
263
+ does and the why you think it should be merged.
264
+
265
+ [dco]: licences/dco.txt
266
+ [hoe]: https://github.com/seattlerb/hoe
267
+ [issue-62]: https://github.com/halostatue/minitar/issues/62
268
+ [minitest]: https://github.com/seattlerb/minitest
269
+ [pr-151-commits]: https://github.com/halostatue/minitar/pull/151/commits
270
+ [pr-151]: https://github.com/halostatue/minitar/pull/151
271
+ [qcm]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
272
+ [sign-off]: LICENCE.md#developer-certificate-of-origin
273
+ [standardrb]: https://github.com/standardrb/standard
data/CONTRIBUTORS.md ADDED
@@ -0,0 +1,27 @@
1
+ # Contributors
2
+
3
+ - Austin Ziegler created minitar, based on work originally written by Mauricio
4
+ Fernández for rpa-base.
5
+
6
+ Thanks to everyone who has contributed to minitar:
7
+
8
+ - Akinori MUSHA (knu)
9
+ - Antoine Toulme
10
+ - Curtis Sampson
11
+ - Daniel J. Berger
12
+ - [@dearblue](https://github.com/dearblue)
13
+ - [@inkstak](https://github.com/inkstak)
14
+ - John Prince
15
+ - Jorie Tappa
16
+ - Kazuyoshi Kato
17
+ - Kevin McDermott
18
+ - Matthew Kent
19
+ - Merten Falk
20
+ - Michal Suchanek
21
+ - Mike Furr
22
+ - [@ooooooo-q](https://github.com/ooooooo-q)
23
+ - Pete Fritchman
24
+ - [@sorah](https://github.com/sorah)
25
+ - Vijay ([@bv-vijay](https://github.com/bv-vijay))
26
+ - Yamamoto Kōhei
27
+ - Zach Dennis
data/LICENCE.md ADDED
@@ -0,0 +1,39 @@
1
+ # Licence
2
+
3
+ - SPDX-License-Identifier: [Ruby][ruby-license] OR [BSD-2-Clause][bsd-2-clause]
4
+
5
+ minitar is free software that may be redistributed and/or modified under the
6
+ terms of Ruby’s licence or the Simplified BSD licence.
7
+
8
+ - Copyright 2004–2025 Austin Ziegler and other contributors.
9
+ - Portions copyright 2004 Mauricio Julio Fernández Pradier.
10
+
11
+ ### Simplified BSD Licence
12
+
13
+ See the file [bsdl.txt](docs/bsdl.txt) in the main distribution.
14
+
15
+ ### Ruby's Licence
16
+
17
+ See the file [ruby.txt](docs/ruby.txt) in the main distribution.
18
+
19
+ ## Developer Certificate of Origin
20
+
21
+ All contributors **must** certify they are willing and able to provide their
22
+ contributions under the terms of this project's licences with the certification
23
+ of the [Developer Certificate of Origin (Version 1.1)](licences/dco.txt).
24
+
25
+ Such certification is provided by ensuring that a `Signed-off-by`
26
+ [commit trailer][trailer] is present on every commit:
27
+
28
+ Signed-off-by: FirstName LastName <email@example.org>
29
+
30
+ The `Signed-off-by` trailer can be automatically added by git with the `-s` or
31
+ `--signoff` option on `git commit`:
32
+
33
+ ```sh
34
+ git commit --signoff
35
+ ```
36
+
37
+ [bsd-2-clause]: https://spdx.org/licenses/BSD-2-Clause.html
38
+ [ruby-license]: https://spdx.org/licenses/Ruby.html
39
+ [trailer]: https://git-scm.com/docs/git-interpret-trailers