| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 19:00:49 +02:00
										 |  |  | describe UnpackStrategy do | 
					
						
							|  |  |  |   describe "#extract_nestedly" do | 
					
						
							| 
									
										
										
										
											2018-07-16 20:56:41 +02:00
										 |  |  |     subject(:strategy) { described_class.detect(path) } | 
					
						
							| 
									
										
										
										
											2018-07-16 19:00:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let(:unpack_dir) { mktmpdir } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 20:56:41 +02:00
										 |  |  |     context "when extracting a GZIP nested in a BZIP2" do | 
					
						
							|  |  |  |       let(:file_name) { "file" } | 
					
						
							|  |  |  |       let(:path) { | 
					
						
							|  |  |  |         dir = mktmpdir | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         (dir/"file").write "This file was inside a GZIP inside a BZIP2." | 
					
						
							|  |  |  |         system "gzip", dir.children.first | 
					
						
							|  |  |  |         system "bzip2", dir.children.first | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dir.children.first | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "can extract nested archives" do | 
					
						
							|  |  |  |         strategy.extract_nestedly(to: unpack_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(File.read(unpack_dir/file_name)).to eq("This file was inside a GZIP inside a BZIP2.") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-16 19:00:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-16 20:56:41 +02:00
										 |  |  |     context "when extracting a directory with nested directories" do | 
					
						
							|  |  |  |       let(:directories) { "A/B/C" } | 
					
						
							|  |  |  |       let(:path) { | 
					
						
							|  |  |  |         (mktmpdir/"file.tar").tap do |path| | 
					
						
							|  |  |  |           mktmpdir do |dir| | 
					
						
							|  |  |  |             (dir/directories).mkpath | 
					
						
							| 
									
										
										
										
											2021-04-15 12:17:55 +01:00
										 |  |  |             system "tar", "--create", "--file", path, "--directory", dir, "A/" | 
					
						
							| 
									
										
										
										
											2018-07-16 20:56:41 +02:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "does not recurse into nested directories" do | 
					
						
							|  |  |  |         strategy.extract_nestedly(to: unpack_dir) | 
					
						
							|  |  |  |         expect(Pathname.glob(unpack_dir/"**/*")).to include unpack_dir/directories | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-07-16 19:00:49 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-19 12:45:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     context "when extracting a nested archive" do | 
					
						
							|  |  |  |       let(:basename) { "file.xyz" } | 
					
						
							|  |  |  |       let(:path) { | 
					
						
							|  |  |  |         (mktmpdir/basename).tap do |path| | 
					
						
							|  |  |  |           mktmpdir do |dir| | 
					
						
							|  |  |  |             FileUtils.touch dir/"file.txt" | 
					
						
							| 
									
										
										
										
											2021-04-15 12:17:55 +01:00
										 |  |  |             system "tar", "--create", "--file", path, "--directory", dir, "file.txt" | 
					
						
							| 
									
										
										
										
											2018-07-19 12:45:35 +02:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it "does not pass down the basename of the archive" do | 
					
						
							| 
									
										
										
										
											2018-07-19 12:45:50 +02:00
										 |  |  |         strategy.extract_nestedly(to: unpack_dir, basename: basename) | 
					
						
							| 
									
										
										
										
											2018-07-19 12:45:35 +02:00
										 |  |  |         expect(unpack_dir/"file.txt").to be_a_file | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-16 19:00:49 +02:00
										 |  |  |   end | 
					
						
							|  |  |  | end |