-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fallback to copy symlinks on Windows #9296
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
0365027
c814924
1c8bc39
180c269
de64429
7df9a0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| require "win32/process" | ||
| require "rbconfig" | ||
|
|
||
| TESTUSER = "testuser" | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| system("net user #{TESTUSER} /del 2>NUL") | ||
| system("net user #{TESTUSER} \"Password123+\" /add") || raise | ||
| system("icacls . /grant #{TESTUSER}:(OI)(CI)(IO)(F)") | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| stdout_read, stdout_write = IO.pipe | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cmd = ARGV.join(" ") | ||
| env = { | ||
| "TMP" => "#{Dir.pwd}/tmp", | ||
| "TEMP" => "#{Dir.pwd}/tmp" | ||
| } | ||
| pinfo = Process.create command_line: cmd, | ||
| with_logon: TESTUSER, | ||
| password: "Password123+", | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| cwd: Dir.pwd, | ||
| environment: ENV.to_h.merge(env).map{|k,v| "#{k}=#{v}" }, | ||
| startup_info: { stdout: stdout_write, stderr: stdout_write } | ||
|
|
||
| stdout_write.close | ||
| out = stdout_read.read | ||
| puts out | ||
|
|
||
| # Wait for process to terminate | ||
| sleep 0.1 while !(ecode=Process.get_exitcode(pinfo.process_id)) | ||
|
|
||
| exit ecode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,7 +190,7 @@ def test_add_files_symlink | |
| File.symlink("../lib/code.rb", "lib/code_sym2.rb") | ||
| rescue Errno::EACCES => e | ||
| if Gem.win_platform? | ||
| pend "symlink - must be admin with no UAC on Windows" | ||
| pend "symlink - developer mode must be enabled on Windows" | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else | ||
| raise e | ||
| end | ||
|
|
@@ -583,25 +583,45 @@ def test_extract_tar_gz_symlink_relative_path | |
| tar.add_symlink "lib/foo.rb", "../relative.rb", 0o644 | ||
| end | ||
|
|
||
| begin | ||
| package.extract_tar_gz tgz_io, @destination | ||
| rescue Errno::EACCES => e | ||
| if Gem.win_platform? | ||
| pend "symlink - must be admin with no UAC on Windows" | ||
| else | ||
| raise e | ||
| end | ||
| end | ||
| package.extract_tar_gz tgz_io, @destination | ||
|
|
||
| extracted = File.join @destination, "lib/foo.rb" | ||
| assert_path_exist extracted | ||
| assert_equal "../relative.rb", | ||
| File.readlink(extracted) | ||
| if symlink_supported? | ||
| assert_equal "../relative.rb", | ||
| File.readlink(extracted) | ||
| end | ||
| assert_equal "hi", | ||
| File.read(extracted), | ||
| "should read file content either by following symlink or on Windows by reading copy" | ||
| end | ||
|
|
||
| def test_extract_tar_gz_symlink_directory | ||
| package = Gem::Package.new @gem | ||
| package.verify | ||
|
|
||
| tgz_io = util_tar_gz do |tar| | ||
| tar.add_symlink "link", "lib/orig", 0o644 | ||
| tar.mkdir "lib", 0o755 | ||
| tar.mkdir "lib/orig", 0o755 | ||
| tar.add_file "lib/orig/file.rb", 0o644 do |io| | ||
| io.write "ok" | ||
| end | ||
| end | ||
|
|
||
| package.extract_tar_gz tgz_io, @destination | ||
| extracted = File.join @destination, "link/file.rb" | ||
| assert_path_exist extracted | ||
| if symlink_supported? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small nitpick, maybe it would be easier without this condition and just check that reading the file works and the content is "ok", regardless if it's a symlink or not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a valid addition: If symlinks are supported then a symlink should actually be created. So I wouldn't remove it. |
||
| assert_equal "lib/orig", | ||
| File.readlink(File.dirname(extracted)) | ||
| end | ||
| assert_equal "ok", | ||
| File.read(extracted) | ||
| end | ||
|
|
||
| def test_extract_symlink_into_symlink_dir | ||
| pend "Symlinks not supported or not enabled" unless symlink_supported? | ||
larskanis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| package = Gem::Package.new @gem | ||
| tgz_io = util_tar_gz do |tar| | ||
| tar.mkdir "lib", 0o755 | ||
|
|
@@ -665,14 +685,10 @@ def test_extract_symlink_parent | |
| destination_subdir = File.join @destination, "subdir" | ||
| FileUtils.mkdir_p destination_subdir | ||
|
|
||
| expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError] | ||
|
|
||
| e = assert_raise(*expected_exceptions) do | ||
| e = assert_raise(Gem::Package::SymlinkError) do | ||
| package.extract_tar_gz tgz_io, destination_subdir | ||
| end | ||
|
|
||
| pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e | ||
|
|
||
| assert_equal("installing symlink 'lib/link' pointing to parent path #{@destination} of " \ | ||
| "#{destination_subdir} is not allowed", e.message) | ||
|
|
||
|
|
@@ -700,14 +716,10 @@ def test_extract_symlink_parent_doesnt_delete_user_dir | |
| tar.add_symlink "link/dir", ".", 16_877 | ||
| end | ||
|
|
||
| expected_exceptions = Gem.win_platform? ? [Gem::Package::SymlinkError, Errno::EACCES] : [Gem::Package::SymlinkError] | ||
|
|
||
| e = assert_raise(*expected_exceptions) do | ||
| e = assert_raise(Gem::Package::SymlinkError) do | ||
| package.extract_tar_gz tgz_io, destination_subdir | ||
| end | ||
|
|
||
| pend "symlink - must be admin with no UAC on Windows" if Errno::EACCES === e | ||
|
|
||
| assert_equal("installing symlink 'link' pointing to parent path #{destination_user_dir} of " \ | ||
| "#{destination_subdir} is not allowed", e.message) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.