Showing with 36 additions and 4 deletions.
  1. +3 −0 CHANGELOG.md
  2. +1 −1 LICENSE
  3. +31 −2 lib/puppet/provider/windows_env/windows_env.rb
  4. +1 −1 metadata.json
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v2.2.2
- Updates for Puppet 4 / Ruby 2.1.5 compatibility.

### v2.2.1
- Fixes to prevent autoloading on master from failing

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013-2014 Eric Badger
Copyright 2013-2015 Eric Badger

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
33 changes: 31 additions & 2 deletions lib/puppet/provider/windows_env/windows_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,37 @@ module self::WinAPI

ffi_lib :Advapi32
attach_function :RegLoadKey, :RegLoadKeyA, [:uintptr_t, :pointer, :pointer], :long

attach_function :RegUnLoadKey, :RegUnLoadKeyA, [:uintptr_t, :pointer], :long

# Ruby < 1.9 doesn't know about encoding.
if defined?(::Encoding)
# Workaround for https://bugs.ruby-lang.org/issues/10820 .
attach_function :RegDeleteValue, :RegDeleteValueW, [:uintptr_t, :buffer_in], :long

# Borrowed from Puppet core. Duplicated for old version compatibilty.
def self.from_string_to_wide_string(str, &block)
str.encode!(Encoding::UTF_16LE)
FFI::MemoryPointer.new(:byte, str.bytesize) do |ptr|
# uchar here is synonymous with byte
ptr.put_array_of_uchar(0, str.bytes.to_a)
yield ptr
end
# ptr has already had free called, so nothing to return
nil
end

def self.delete_value(key, name)
result = nil
from_string_to_wide_string(name) do |name_ptr|
result = RegDeleteValue(key.hkey, name_ptr)
end
result
end
else
def self.delete_value(key, name)
key.delete_value(name)
end
end
end
end

Expand Down Expand Up @@ -193,7 +222,7 @@ def destroy
debug "Removing value from environment variable '#{@resource[:variable]}', or removing variable itself"
case @resource[:mergemode]
when :clobber
key_write { |key| key.delete_value(@resource[:variable]) }
key_write { |key| self.class::WinAPI.delete_value(key, @resource[:variable]) }
when :insert, :append, :prepend
remove_value
key_write
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "badgerious-windows_env",
"version": "2.2.1",
"version": "2.2.2",
"author": "badgerious",
"summary": "Manages Windows environment variables",
"license": "Apache License, Version 2.0",
Expand Down