<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# PURPOSE: this strategy is atomic and preserves default umasks, but on windows you must
#          not be copying from the temp directory, and will not correctly restore
#          SELinux contexts.
#

class Chef
  class Provider
    class File
      class Deploy
        class MvWindows
          def create(file)
            Chef::Log.debug("touching #{file} to create it")
            FileUtils.touch(file)
          end

          def deploy(src, dst)
            if ::File.dirname(src) != ::File.dirname(dst)
              Chef::Log.warn("WARNING: moving tempfile across different directories -- this may break inherited permissions")
            end

            FileUtils.mv(src, dst)
          end
        end
      end
    end
  end
end<commit_msg>better handling of windows ACLs<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# We update the contents of the file, using mv for atomicity, while maintaining all the
# ACL information on the dst file.
#

require 'chef/win32/security'

class Chef
  class Provider
    class File
      class Deploy
        class MvWindows
          def create(file)
            Chef::Log.debug("touching #{file} to create it")
            FileUtils.touch(file)
          end

          ALL_ACLS =
            Chef::ReservedNames::Win32::Security::OWNER_SECURITY_INFORMATION |
            Chef::ReservedNames::Win32::Security::GROUP_SECURITY_INFORMATION |
            Chef::ReservedNames::Win32::Security::DACL_SECURITY_INFORMATION
            #Chef::ReservedNames::Win32::Security::SACL_SECURITY_INFORMATION

          def deploy(src, dst)
            result = Chef::ReservedNames::Win32::Security.get_named_security_info(dst, :SE_FILE_OBJECT, ALL_ACLS)

            Chef::Log.debug("applying owner #{result.owner} to staged file")
            Chef::Log.debug("applying group #{result.group} to staged file")
            Chef::Log.debug("applying dacl #{result.dacl} to staged file")
            Chef::Log.debug("applying dacl inheritance to staged file") if result.dacl_inherits?

            # FIXME: SACL
            # FIXME: inheritance
            # FIXME: control?
            # FIXME: filter out inherited DACLs

            so = Chef::ReservedNames::Win32::Security::SecurableObject.new(src)

            so.set_dacl(result.dacl, result.dacl_inherits?)

            so.group = result.group

            so.owner = result.owner

            #so.set_sacl(result.sacl, result.sacl_inherits?)

            FileUtils.mv(src, dst)
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09017671517671517, 'fraction_numerical': 0.008835758835758836, 'mean_word_length': 2.747809152872444, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5990513', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1055, 'n_words': 371}