Commit Graph

1384 Commits

Author SHA1 Message Date
Robert Haines f1e8c2fc9d Fix Style/StringConcatenation cop. 2021-06-18 16:10:57 +01:00
Robert Haines f66a15a85d Update rubocop config. 2021-06-18 16:00:57 +01:00
Robert Haines 71f2c90b20 Test that a corrupted cdir entry is caught. 2021-06-18 12:08:31 +01:00
Robert Haines 75386f8db6 Remove now redundant `IOizeString` module. 2021-06-18 11:50:07 +01:00
Robert Haines afe1892208 Fix a mis-firing CentralDirectory test.
`test_read_from_truncated_zip_file` was not testing what it thought it
was. It was testing whether we caught an out-of-bounds cdir offset, not
whether we caught a corrupted cdir entry.

This commit embraces the actual behaviour and tests that we catch an
out-of-bounds error for both standard `IO`s and `StringIO`s.
2021-06-18 11:44:58 +01:00
Robert Haines bf3ae2ad76 Improve some entry header tests.
Use `StringIO` instead of the custom `IOizeString` code in the
test_helper.

Also test both versions (class and instance) of the `Entry` APIs.
2021-06-18 11:11:11 +01:00
Robert Haines 750c474610 Update Changelog. 2021-06-12 16:31:50 +01:00
Robert Haines 21ba82c67c Move the split signature to the constants file. 2021-06-12 16:29:25 +01:00
Robert Haines 80382135e5 Tidy up some of the file split code. 2021-06-12 16:29:25 +01:00
Robert Haines bd2f15e4bb Extract the `Zip::File::split` code into its own module.
This code is rarely used and may not even be correct according to the
standard. Also this de-clutters the `File` class.
2021-06-12 16:29:06 +01:00
Robert Haines 7df623fb0e Read EOCD record for Zip64 files.
Means we actually read in the file-level comment now!

Fixes #492.
2021-06-11 23:23:34 +01:00
Robert Haines be1c5b7c03 Turn on FULL_ZIP64_TEST in CI. 2021-06-11 17:28:52 +01:00
Robert Haines 3fbb48de31 Refactor the full 64bit tests. 2021-06-11 17:28:52 +01:00
Robert Haines d8111826bf Remove the now redundant `read_zip_*` methods.
We're unpacking headers in chunks now, using `unpack`.
2021-06-11 13:51:40 +01:00
Robert Haines dc27c99eb1 Refactor unpacking the Zip64 eocd record. 2021-06-11 13:50:09 +01:00
Robert Haines 7e254dc581 Refactor unpacking the eocd record.
The old version used some really obfuscated code to perform what is an
essentially fairly simple job.
2021-06-10 22:44:51 +01:00
Robert Haines cd9a3fcad1 Move all the `read_zip_*` methods out of `Entry`.
They were only ever used in `CentralDirectory` anyway.
2021-06-10 17:29:00 +01:00
Robert Haines c0f20321ae Merge branch 'fix_depreciation_warning' of https://github.com/bbuchalter/rubyzip into bbuchalter-fix_depreciation_warning
* 'fix_depreciation_warning' of https://github.com/bbuchalter/rubyzip:
  Use default ruby behavior for Array.join
  Remove OUTPUT_FIELD_SEPARATOR-related test behaviors
  Set OUTPUT_FIELD_SEPARATOR to nil in test
  Prefer OUTPUT_RECORD_SEPARATOR to $\
  Prefer OUTPUT_FIELD_SEPARATOR to $,
2021-06-07 20:02:15 +01:00
Robert Haines 51c6c10e7a Add a compatibility table to the README.
Fixes #455.
2021-06-06 20:06:59 +01:00
Robert Haines 4fe6bc8983 Update README to remove link to Travis. 2021-06-06 18:11:41 +01:00
Jan-Joost Spanjers 4a01537f32 Fix restore permissons test on Windows 2021-06-06 16:17:22 +01:00
Jan-Joost Spanjers 52bcfc72f9 Revert "REVERT ME: This disables a test fixed by #486"
This reverts commit 6ac2cb207d.
2021-06-06 16:17:22 +01:00
Robert Haines 369056ff30 Update Changelog. 2021-06-06 16:17:22 +01:00
Robert Haines 2410f2889e Restore file timestamps on all platforms.
Was only being done on Unix-type filesystems for some reason. Moved code
so that it is run for all files, whatever the underlying platform.
2021-06-06 16:17:22 +01:00
Robert Haines 3260e4e666 Add some tests to ensure the default behaviour sticks. 2021-06-06 16:17:22 +01:00
Robert Haines a6c6345084 Set restoring permissions and times as the default. 2021-06-06 16:17:22 +01:00
Robert Haines 684b69f330 Move the restore options to the top level.
This will ensure consistency between `File` and `Entry`.
2021-06-06 16:17:22 +01:00
Robert Haines 098bce399a Update Changelog. 2021-06-06 15:45:04 +01:00
Robert Haines a4e51f15fc Use constants instead of literals for some `fstype` calls. 2021-06-06 15:02:49 +01:00
Robert Haines 26b7f98c08 Use octal for more obvious definition of file-modes. 2021-06-06 15:02:49 +01:00
Robert Haines 9d8fc05c43 Refactor `get_entry` in `FileSystem::File(::Stat)`.
Rename it to `find_entry` because that is ultimately what is called on
the underlying zip file. Make `FileSystem::File#find_entry` public as it
need to be called from `FileSystem::File::Stat`, so now we can avoid
`__send__`. Neither class is documented anyway, so no harm done there.
2021-06-06 15:02:49 +01:00
Robert Haines 64a162ced4 Refactor `FileSystem::File::Stat.delegate_to_fs_file`.
Now uses `class_exec` instead of `class_eval`.
2021-06-06 15:02:49 +01:00
Robert Haines 99ecf3638f Remove spurious empty line at start of module. 2021-06-06 15:02:49 +01:00
Robert Haines 7b2e9c7970 Extract `FileSystem::File::Stat` from `FileSystem::File`. 2021-06-06 15:02:49 +01:00
Robert Haines d1329299c3 Extract `FileSystem::File` from the main filesystem file. 2021-06-06 15:02:49 +01:00
Robert Haines a1c9b63e61 Extract `FileSystem::Dir` from the main filesystem file. 2021-06-06 15:02:49 +01:00
Robert Haines 239baef845 Extract `DirectoryIterator` from the main filesystem file. 2021-06-06 15:02:49 +01:00
Robert Haines 204d084fdf Extract `ZipFileNameMapper` from the main filesystem file. 2021-06-06 15:02:49 +01:00
Robert Haines 64c54cc61b Update Changelog. 2021-06-06 14:56:29 +01:00
Jan-Joost Spanjers 6ac2cb207d REVERT ME: This disables a test fixed by #486 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers 8a24bff1b2 Disable recover file permissions test on Windows 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers c3443c06ea Make recover file permissions test better understandable 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers cdef4a5187 Prevent directory not empty error when running file_test on Windows
Fixed error:

ZipFileTest#test_open_buffer_no_op_does_not_change_file:
Errno::ENOTEMPTY: Directory not empty @ dir_s_rmdir - D:/a/_temp/d20210605-6612-1yi35sp
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1335:in `rmdir'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1335:in `block in remove_dir1'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1349:in `platform_support'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1334:in `remove_dir1'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1327:in `remove'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:689:in `block in remove_entry'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1384:in `ensure in postorder_traverse'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:1384:in `postorder_traverse'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/fileutils.rb:687:in `remove_entry'
    C:/hostedtoolcache/windows/Ruby/2.4.10/x64/lib/ruby/2.4.0/tmpdir.rb:101:in `mktmpdir'
    D:/a/rubyzip/rubyzip/test/file_test.rb:136:in `test_open_buffer_no_op_does_not_change_file'

Rationale:

File#dup does not behave like what you would expect from #dup on Ruby.
File#dup calls dup(2), which has OS dependant behavoir.

On Windows, calling File#dup seems to cause an extra reference
to an open file, which prevents deleting that file later.

With this commit, we leave out the call to File#dup on Windows.
It is not clear to me that removing this call has no undesired
consequences, but all other existing tests still succeed.
2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers 8a5fef8074 Fix FileSystem::ZipFileNameMapper#expand_path on Windows
Fixes regression introduced by 0e4dc676a0.
2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers c7fe2a47cb Do not hardcode /tmp in entry_test 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers 5c9b850729 Prevent adding a newline to comments for generated test files on Windows 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers 0051d5bb1f Read/write test files in binay mode (for Windows compatibility) 2021-06-06 14:44:20 +01:00
Jan-Joost Spanjers cf22ff1b92 Preserve eol linefeed for text test data files
This prevents converting lf to crlf on Windows.
2021-06-06 14:44:20 +01:00
Robert Haines b705085b09 `Entry#name_safe?` now allows Windows drive mappings. 2021-06-06 14:44:20 +01:00
Robert Haines 22a54853e6 Reinstate normalising pathname separators to `/`.
But only do it after we have set filename encoding appropriately to
avoid breaking multibyte characters with `\`s in them.

Fixes #324.
2021-06-04 16:22:45 +01:00