File: vcsrepo.rb

package info (click to toggle)
puppet-module-puppetlabs-vcsrepo 1.3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, trixie
  • size: 828 kB
  • sloc: ruby: 6,359; sh: 44; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 969 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'tmpdir'
require 'digest/md5'
require 'fileutils'

# Abstract
class Puppet::Provider::Vcsrepo < Puppet::Provider

  private

  def set_ownership
    owner = @resource.value(:owner) || nil
    group = @resource.value(:group) || nil
    FileUtils.chown_R(owner, group, @resource.value(:path))
  end

  def path_exists?
    File.directory?(@resource.value(:path))
  end

  def path_empty?
    # Path is empty if the only entries are '.' and '..'
    d = Dir.new(@resource.value(:path))
    d.read # should return '.'
    d.read # should return '..'
    d.read.nil?
  end

  # Note: We don't rely on Dir.chdir's behavior of automatically returning the
  # value of the last statement -- for easier stubbing.
  def at_path(&block) #:nodoc:
    value = nil
    Dir.chdir(@resource.value(:path)) do
      value = yield
    end
    value
  end

  def tempdir
    @tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path)))
  end

end