| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 20:59:21 +02:00
										 |  |  | require_relative "shared_examples" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe UnpackStrategy::Directory do | 
					
						
							| 
									
										
										
										
											2018-09-20 09:07:56 +01:00
										 |  |  |   subject(:strategy) { described_class.new(path) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   let(:path) do | 
					
						
							| 
									
										
										
										
											2018-07-23 20:59:21 +02:00
										 |  |  |     mktmpdir.tap do |path| | 
					
						
							|  |  |  |       FileUtils.touch path/"file" | 
					
						
							|  |  |  |       FileUtils.ln_s "file", path/"symlink" | 
					
						
							| 
									
										
										
										
											2019-05-17 00:41:57 +02:00
										 |  |  |       FileUtils.mkdir path/"folder" | 
					
						
							|  |  |  |       FileUtils.ln_s "folder", path/"folderSymlink" | 
					
						
							| 
									
										
										
										
											2018-07-23 20:59:21 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-09-20 09:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 20:59:21 +02:00
										 |  |  |   let(:unpack_dir) { mktmpdir } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "does not follow symlinks" do | 
					
						
							|  |  |  |     strategy.extract(to: unpack_dir) | 
					
						
							|  |  |  |     expect(unpack_dir/"symlink").to be_a_symlink | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-17 00:41:57 +02:00
										 |  |  |   it "does not follow top level symlinks to directories" do | 
					
						
							|  |  |  |     strategy.extract(to: unpack_dir) | 
					
						
							|  |  |  |     expect(unpack_dir/"folderSymlink").to be_a_symlink | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-23 20:59:21 +02:00
										 |  |  |   it "preserves permissions of contained files" do | 
					
						
							|  |  |  |     FileUtils.chmod 0644, path/"file" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     strategy.extract(to: unpack_dir) | 
					
						
							|  |  |  |     expect((unpack_dir/"file").stat.mode & 0777).to eq 0644
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it "preserves the permissions of the destination directory" do | 
					
						
							|  |  |  |     FileUtils.chmod 0700, path | 
					
						
							|  |  |  |     FileUtils.chmod 0755, unpack_dir | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     strategy.extract(to: unpack_dir) | 
					
						
							|  |  |  |     expect(unpack_dir.stat.mode & 0777).to eq 0755
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |