Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Zip::FileSystem::ZipFsDir#glob #363

Merged
merged 2 commits into from Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/zip/filesystem.rb
Expand Up @@ -573,6 +573,10 @@ def get_output_stream(fileName, permissionInt = nil, &aProc)
@zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
end

def glob(pattern, *flags, &block)
@zipFile.glob(expand_to_entry(pattern), *flags, &block)
end

def read(fileName)
@zipFile.read(expand_to_entry(fileName))
end
Expand Down
28 changes: 23 additions & 5 deletions test/filesystem/directory_test.rb
Expand Up @@ -3,6 +3,7 @@

class ZipFsDirectoryTest < MiniTest::Test
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
GLOB_TEST_ZIP = 'test/data/globTest.zip'

def setup
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
Expand Down Expand Up @@ -93,11 +94,28 @@ def test_chroot
end
end

# Globbing not supported yet
# def test_glob
# # test alias []-operator too
# fail "implement test"
# end
def test_glob
globbed_files = [
'globTest/foo/bar/baz/foo.txt',
'globTest/foo.txt',
'globTest/food.txt'
]

::Zip::File.open(GLOB_TEST_ZIP) do |zf|
zf.dir.glob('**/*.txt') do |f|
assert globbed_files.include?(f.name)
end

zf.dir.glob('globTest/foo/**/*.txt') do |f|
assert_equal globbed_files[0], f.name
end

zf.dir.chdir('globTest/foo')
zf.dir.glob('**/*.txt') do |f|
assert_equal globbed_files[0], f.name
end
end
end

def test_open_new
::Zip::File.open(TEST_ZIP) do |zf|
Expand Down