Sha256: 58a64aa88092e502589a569996973e487e1b91158ff214771765245f1aae9e36

Contents?: true

Size: 1.75 KB

Versions: 74

Compression:

Stored size: 1.75 KB

Contents

#
# Author:: Lamont Granquist (<lamont@opscode.com>)
# 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.
#

require "tempfile"

class Chef
  class FileContentManagement
    class Tempfile

      attr_reader :new_resource

      def initialize(new_resource)
        @new_resource = new_resource
      end

      def tempfile
        @tempfile ||= tempfile_open
      end

      private

      def tempfile_open
        tf = ::Tempfile.open(tempfile_basename, tempfile_dirname)
        # We always process the tempfile in binmode so that we
        # preserve the line endings of the content.
        tf.binmode
        tf
      end

      #
      # These are important for windows to get permissions right, and may
      # be useful for SELinux and other ACL approaches.  Please use them
      # as the arguments to Tempfile.new() consistently.
      #
      def tempfile_basename
        basename = ::File.basename(@new_resource.name)
        basename.insert 0, "." unless Chef::Platform.windows?  # dotfile if we're not on windows
        basename
      end

      def tempfile_dirname
        Chef::Config[:file_staging_uses_destdir] ? ::File.dirname(@new_resource.path) : Dir::tmpdir
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
chef-11.18.12-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.18.12 lib/chef/file_content_management/tempfile.rb
chef-11.18.6-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.18.6 lib/chef/file_content_management/tempfile.rb
chef-11.18.0-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.18.0 lib/chef/file_content_management/tempfile.rb
chef-11.16.4-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.16.4 lib/chef/file_content_management/tempfile.rb
chef-11.16.2-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.16.2 lib/chef/file_content_management/tempfile.rb
chef-11.16.0-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.16.0 lib/chef/file_content_management/tempfile.rb
chef-11.16.0.rc.0 lib/chef/file_content_management/tempfile.rb
chef-11.14.6-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.14.6 lib/chef/file_content_management/tempfile.rb
chef-11.14.2-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.14.2 lib/chef/file_content_management/tempfile.rb
chef-11.14.0.rc.2-x86-mingw32 lib/chef/file_content_management/tempfile.rb
chef-11.14.0.rc.2 lib/chef/file_content_management/tempfile.rb
chef-11.14.0.alpha.4 lib/chef/file_content_management/tempfile.rb