Sha256: bf44d5bbe46fd8d3f1ddc5acda33337419bb06d3876835305ffcd9c8270220ff

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

require 'puppet/indirector/terminus'

# An empty terminus type, meant to just return empty objects.
class Puppet::Indirector::File < Puppet::Indirector::Terminus
    # Remove files on disk.
    def destroy(request)
        if respond_to?(:path)
            path = path(request.key)
        else
            path = request.key
        end
        raise Puppet::Error.new("File %s does not exist; cannot destroy" % [request.key]) unless File.exist?(path)

        begin
            File.unlink(path)
        rescue => detail
            raise Puppet::Error, "Could not remove %s: %s" % [request.key, detail]
        end
    end

    # Return a model instance for a given file on disk.
    def find(request)
        if respond_to?(:path)
            path = path(request.key)
        else
            path = request.key
        end

        return nil unless File.exist?(path)

        begin
            content = File.read(path)
        rescue => detail
            raise Puppet::Error, "Could not retrieve path %s: %s" % [path, detail]
        end

        return model.new(content)
    end

    # Save a new file to disk.
    def save(request)
        if respond_to?(:path)
            path = path(request.key)
        else
            path = request.key
        end
        dir = File.dirname(path)

        raise Puppet::Error.new("Cannot save %s; parent directory %s does not exist" % [request.key, dir]) unless File.directory?(dir)

        begin
            File.open(path, "w") { |f| f.print request.instance.content }
        rescue => detail
            raise Puppet::Error, "Could not write %s: %s" % [request.key, detail]
        end
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puppet-0.24.9 lib/puppet/indirector/file.rb
puppet-0.24.5 lib/puppet/indirector/file.rb
puppet-0.24.6 lib/puppet/indirector/file.rb
puppet-0.24.7 lib/puppet/indirector/file.rb
puppet-0.24.8 lib/puppet/indirector/file.rb