diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-10-16 16:31:50 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-10-16 16:31:50 -0700 |
commit | 15cc05300b33e67d27c00fd7c399b9e75a235bd8 (patch) | |
tree | fb430ae387c836bb1442bdcef6bc5c0a4133b797 | |
parent | b7fdc65adb93f614c27efb48c3d1c3fb9b1911f7 (diff) | |
download | chef-faster_windows_symlinks.tar.gz |
Avoid making WMI calls to find the windows version on each symlink creationfaster_windows_symlinks
We can gather this information via ChefUtils which abstracts the Ohai data. That way we only make these WMI calls once.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/win32/file.rb | 3 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index 55fc2461e8..7a019781d7 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -23,6 +23,7 @@ require_relative "api/security" require_relative "error" require_relative "unicode" require_relative "version" +require "chef-utils" unless defined?(ChefUtils::CANARY) class Chef module ReservedNames::Win32 @@ -62,7 +63,7 @@ class Chef # TODO do a check for CreateSymbolicLinkW and # raise NotImplemented exception on older Windows flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0 - flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE if Chef::ReservedNames::Win32::Version.new.win_10_creators_or_higher? + flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE if ChefUtils.windows_nt_version >= "10.0.15063" # Windows 10 Creators Update or later old_name = encode_path(old_name) new_name = encode_path(new_name) unless CreateSymbolicLinkW(new_name, old_name, flags) diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index c83e52e4fc..f4c182e082 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -22,6 +22,7 @@ require "wmi-lite/wmi" class Chef module ReservedNames::Win32 + # @deprecated This isn't used anywhere in chef/chef and should be avoided if at all possible as each time it's used expensive WMI calls have to be made. Windows version should be fetched from chef-utils instead class Version class << self include Chef::ReservedNames::Win32::API::System |