From 7c6ef6bff121a22a9346c8559196e5661551df32 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 5 Mar 2020 20:37:08 -0800 Subject: link resource: Remove checks for link support on Windows 2008+ have support for links. There's no reason to perform this check every time on Windows. It's just wasting CPU cycles Signed-off-by: Tim Smith --- lib/chef/resource/link.rb | 23 +---------------------- lib/chef/win32/file.rb | 12 ++---------- spec/unit/provider/link_spec.rb | 3 +-- spec/unit/resource/link_spec.rb | 6 +----- 4 files changed, 5 insertions(+), 39 deletions(-) diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index df4ab81dd1..8c9e522b87 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Tyler Cloke () -# Copyright:: Copyright 2008-2019, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -44,11 +44,6 @@ class Chef default_action :create allowed_actions :create, :delete - def initialize(name, run_context = nil) - verify_links_supported! - super - end - property :target_file, String, description: "An optional property to set the target file if it differs from the resource block's name.", name_property: true, identity: true @@ -73,22 +68,6 @@ class Chef def path target_file end - - private - - # On certain versions of windows links are not supported. Make - # sure we are not on such a platform. - def verify_links_supported! - if ChefUtils.windows? - require_relative "../win32/file" - begin - Chef::ReservedNames::Win32::File.verify_links_supported! - rescue Chef::Exceptions::Win32APIFunctionNotImplemented => e - Chef::Log.fatal("Link resource is not supported on this version of Windows") - raise e - end - end - end end end end diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 4fac3fe797..ccbff43f01 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -1,7 +1,7 @@ # # Author:: Seth Chisamore () -# Author:: Mark Mzyk () -# Copyright:: Copyright 2011-2016, Chef Software Inc. +# Author:: Mark Mzyk () +# Copyright:: Copyright 2011-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -166,14 +166,6 @@ class Chef VersionInfo.new(file_name) end - def self.verify_links_supported! - CreateSymbolicLinkW(nil) - rescue Chef::Exceptions::Win32APIFunctionNotImplemented => e - raise e - rescue Exception - # things are ok. - end - def self.file_access_check(path, desired_access) security_descriptor = Chef::ReservedNames::Win32::Security.get_file_security(path) token_rights = Chef::ReservedNames::Win32::Security::TOKEN_IMPERSONATE | diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index 154197e730..30c752b5ea 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -1,7 +1,7 @@ # # Author:: AJ Christensen () # Author:: John Keiser () -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -358,7 +358,6 @@ describe Chef::Resource::Link do allow(Chef::Resource::Link).to receive(:new).with( provider.new_resource.name ).and_return(resource_link) - allow(resource_link).to receive(:verify_links_supported!) allow(ChefUtils).to receive(:windows?).and_return(true) end diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index ae32e4aa30..792305ee55 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Tyler Cloke () -# Copyright:: Copyright 2008-2017, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,10 +22,6 @@ require "spec_helper" describe Chef::Resource::Link do let(:resource) { Chef::Resource::Link.new("fakey_fakerton") } - before(:each) do - expect_any_instance_of(Chef::Resource::Link).to receive(:verify_links_supported!).and_return(true) - end - it "the target_file property is the name_property" do expect(resource.target_file).to eql("fakey_fakerton") end -- cgit v1.2.1