Commit Graph

1423 Commits

Author SHA1 Message Date
Robert Haines 14ff11ba05 Re-initialize CDir after a `commit`.
Using the factored-out code preserves options set in `File`.

Fixes #529.
2022-06-25 08:51:32 +01:00
Robert Haines c243b4429a Factor out the code in `File` to init the CDir.
This allows us to reuse it without overwriting any options passed to `File`.
2022-06-25 08:48:23 +01:00
Robert Haines 6486047d5f Use the new `Entry` time methods in `Filesystem::File`. 2022-06-20 17:18:20 +01:00
Robert Haines 466383ff1a Add other `Entry` time methods and test them all. 2022-06-20 17:18:20 +01:00
Robert Haines fff1f8ea8a Add `Entry#mtime=` as an alias of `Entry#time=`. 2022-06-20 17:18:20 +01:00
Robert Haines 62ed397b1a Generalize `Entry#time=`.
So we can use it for `atime=`, `ctime=` and `utime=` as well.
2022-06-20 17:18:20 +01:00
Robert Haines d6482bd567 Generalize `Entry#time`.
So we can use it for `atime`, `ctime` and `utime` as well.
2022-06-20 17:18:20 +01:00
Robert Haines ae0262df2e Add `Entry#zip64?` as a better way detect Zip64 entries. 2022-06-20 17:18:20 +01:00
Robert Haines 307fc6c6e9 Mark other mutating methods in `Entry` as dirty.
Also, remove `Entry#extra=` as it makes no sense (and wasn't even being
tested).

And remove slightly odd test that was assuming an archive would not be
changed if its utime was changed - even if it was being changed back
immediately. This test was merely confirming that we weren't catching
timestamp changes correctly.
2022-06-20 17:18:20 +01:00
Robert Haines 33dce510a6 Remove `Entry#dirty=` as 'dirtyness' is now monitored internally.
Had to round out some of the accessors that mark an `Entry` as dirty.
2022-06-20 17:18:20 +01:00
Robert Haines 5cd1ef2910 Use new dirty statuses to detect zip file changes.
This also means that we no longer need to keep a copy of the original
set of `Entry`s or the central directory comment to test for changes.

For situations where a zip file has a lot of entries (e.g. #506) this
means we save a lot of memory, and a lot of time constructing the zip
file in memory.
2022-06-20 17:18:20 +01:00
Robert Haines 08641db9f8 Make `CentralDirectory` dirtyable. 2022-06-20 17:18:20 +01:00
Robert Haines 7b340d62a6 Abstract marking as dirty into `Dirtyable` for reuse. 2022-06-20 17:18:20 +01:00
Robert Haines 3002251048 Mark certain methods in `Entry` as making it dirty.
This allows us to track which entries have changed without keeping a
copy of all entries. I hope.
2022-06-20 17:18:19 +01:00
Robert Haines 78a3cc596f Make `Entry::zipfile` private.
No need for it to be public, and especially not writeable.
2022-06-20 17:18:19 +01:00
Robert Haines e0e754ae65 Switch how the `Entry::dirty` flag is used.
Set it to true by default - because a new `Entry` is dirty by
definition, having not been written yet. Then make sure that an `Entry`
that is created by reading from a zip file is set as not dirty.
2022-06-20 17:18:19 +01:00
Robert Haines 48d6acf9ca Ensure all streams passed to `File.new` are in `binmode`.
Previously, only those streams that were passed to `new` by `open_buffer`
were in the correct mode.
2022-06-18 16:19:52 +01:00
Robert Haines 513ce5e5f7 Remove unnecessary encoding change in tests for `File`. 2022-06-18 12:45:59 +01:00
Finn Bacall 451a04f7a2 Test for `Errno::ENOENT` 2022-06-16 20:31:35 +01:00
Finn Bacall 8b87b0e200 Implement `Zip::FileSystem::ZipFsFile#symlink?` 2022-06-16 20:31:35 +01:00
Robert Haines ffa90a37cb README: improve the crypto documentation.
Clean it up and provide a decryption example.
2022-04-23 13:54:09 +01:00
Robert Haines e07f019507 Improve the description of `InputStream#get_next_entry`.
Documentation now refects the fact that the stream is positioned at the start
of the entry data.
2022-04-23 13:52:50 +01:00
naoto hamada 243a66496a Fix indent 2022-04-09 07:48:45 +01:00
Robert Haines d2789dd0e3 Add a note to the README about 2.3 compatibility.
Closes #520.
2022-02-06 15:03:01 +00:00
Robert Haines 05a1739069 Properly test `File#mkdir`. 2022-01-22 08:39:43 +00:00
Robert Haines 31e6688528 Remove unused private method `File#directory?`.
This was a fairly horrible method anyway, for a number of reasons. It
looked like a method that tested whether a name was a 'directory' name
or not, and it did, but it also had some side effects where it would
convert it *to* a directory name in some cases as well. Thankfully,
nothing was using it any more, and as it was private we can lose it
safely. Gone.
2022-01-22 07:38:18 +00:00
Robert Haines e2e0e23763 Remove `File::add_buffer` from the API.
Its functionality is now replicated in `File::open_buffer` but in a more
secure way.
2022-01-22 07:34:00 +00:00
Robert Haines 044759f502 Fix `OutputStream#put_next_entry` to preserve `StreamableStream`s.
When passing an `Entry` type to `File#get_output_stream` the entry is
used to create a `StreamableStream`, which preserves all the info in the
entry, such as timestamp, etc. But then in `put_next_entry` all that is
lost due to the test for `kind_of?(Entry)` which a `StreamableStream` is
not. See #503 for details.

This change tests for `StreamableStream`s in `put_next_entry` and uses
them directly. Some set-up within `Entry` needed to be made more robust
to cope with this, but otherwise it's a low impact change, which does
fix the problem.

The reason this case was being missed before is that the tests weren't
testing `get_output_stream` with an `Entry` object, so I have also added
that test too.

Fixes #503.
2022-01-20 19:29:40 +00:00
Robert Haines 4cf801c5f3 Tidy up `EntrySet` accessors.
`entry_order` is no longer a member, so remove it. `entry_set` should
not be public, but needs to be protected for use in `==`.
2022-01-18 20:09:34 +00:00
Robert Haines 8489ab07d1 `OutputStream`: use a `CentralDirectory` object internally.
Now `CentralDirectory` is a bit cleaner it actually makes sense to use
it here instead of an `EntrySet` and comment separately.
2022-01-17 22:32:56 +00:00
Robert Haines 60f8fffbc2 Reorder methods in `CentralDirectory` with private at the end. 2022-01-17 22:04:45 +00:00
Robert Haines bdbd573290 Remove unnecessary static method from `CentralDirectory`.
`CentralDirectory` shouldn't be in the public API for rubyzip and
there's nothing that `CentralDirectory::read_from_stream` did that
couldn't be done by just initializing an object first. Keeping it around
risked things getting out of date as we streamline and fix other things.
2022-01-17 18:10:17 +00:00
Robert Haines 75503df682 Round out the max comment size tests.
Just sanity check the comment size and the number of entries once the
file has been initialized.
2022-01-17 18:03:04 +00:00
Robert Haines 9c3f8254c7 Fix reading zip64 files with max length file comment.
If a zip file has a comment that is 65,535 characters long - which is a
valid length and the maximum allowable length - the initial read of the
archive fails to find the Zip64 End of Central Directory Locator and
therefore cannot read the rest of the file.

This commit fixes this by making sure that we look far enough back into
the file from the end to find this locator, and then use the
information in it to find the Zip64 End of Central Directory Record.

Test added to catch regressions.

Fixes #509.
2022-01-17 18:02:39 +00:00
Robert Haines 1d6bfb7e69 Expose the `EntrySet` more cleanly through `CentralDirectory`.
There is now no direct access to the set of entries in a central
directory. This makes the interface cleaner because we now, for example,
add/delete things directly to/from the central directory, rather than
to/from the entry set contained within the central directory.
2022-01-16 11:53:40 +00:00
Robert Haines 34731b1885 `Zip::File` no longer subclasses `Zip::CentralDirectory`.
It has bothered me for years that the central directory is exposed in
this way. A zip file should *have* a central directory, but it should
not *be* one.

This commit starts us down the path of properly separating the two.
2022-01-15 13:10:54 +00:00
Robert Haines f8b9d07022 Round out EOCD data size constants in CDir. 2022-01-12 09:13:15 +00:00
Robert Haines b1b82bbd9e Tidy up updating notes in README. 2022-01-11 22:26:50 +00:00
Robert Haines 7f7c4ca194 Update README after the move to Ruby >= 2.5. 2022-01-11 22:26:50 +00:00
Robert Haines cf258bbb71 Move to ruby 2.5 as the earliest supported version.
2.4 is nearly two years beyond EOL now.

Closes #484.
2022-01-11 22:26:09 +00:00
Robert Haines 90728d7109 Add `-v` switch to ruby for all tests. 2022-01-11 13:24:35 +00:00
Robert Haines 20952ef38f Update version numbers in the README test matrix. 2022-01-11 13:19:31 +00:00
Robert Haines 3fbc5e62f9 Add the YJIT tests to the README matrix. 2022-01-11 13:15:48 +00:00
Robert Haines 9bed9d0539 Expand the YJIT tests into a mini matrix.
Test 3.1 and head on Ubuntu and MacOS.
2022-01-11 13:02:00 +00:00
Robert Haines 099d379c82 Add an extra test for YJIT in ruby 3.1.
I tried adding this to the matrix, but I couldn't work out how to do
this *and* keep a vanilla 3.1 test in the mix as well. It seems you
can't add different `env`s with `include`, but maybe I missed something.
2022-01-10 18:16:00 +00:00
Robert Haines e04c9cdbd8 Update compatibility matrix in the README. 2022-01-02 13:57:09 +00:00
Robert Haines 8f743d7f68 Make ruby versions list in the CI consistent.
Ruby version `3.0` must be quoted otherwise it's interpreted as `3`.
Might as well make the rest in the list consistent.
2022-01-02 13:09:06 +00:00
Taichi Ishitani 1c33f2dd90 add Ruby 3.1 to CI 2022-01-02 13:06:07 +00:00
Robert Haines 14b63f68db Ensure `File.open_buffer` doesn't rewrite unchanged data. 2021-11-30 22:22:37 +00:00
Robert Haines f5e19db273 Add a 100,000 file zip to test `count_entries`. 2021-11-20 20:02:47 +00:00