Module: Librarian::Puppet::Util

Instance Method Summary collapse

Instance Method Details

#clean_uri(uri) ⇒ Object

Remove user and password from a URI object



60
61
62
63
64
65
# File 'lib/librarian/puppet/util.rb', line 60

def clean_uri(uri)
  new_uri = uri.clone
  new_uri.user = nil
  new_uri.password = nil
  new_uri
end

#cp_r(src, dest) ⇒ Object

workaround Issue #173 FileUtils.cp_r will fail if there is a symlink that points to a missing file or when the symlink is copied before the target file when preserve is true see also tickets.opscode.com/browse/CHEF-833

If the rsync configuration parameter is set, use rsync instead of FileUtils



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/librarian/puppet/util.rb', line 29

def cp_r(src, dest)
  if rsync?
    if Gem.win_platform?
      src_clean = "#{src}".gsub(/^([a-z]):/i, '/cygdrive/\1')
      dest_clean = "#{dest}".gsub(/^([a-z]):/i, '/cygdrive/\1')
    else
      src_clean = src
      dest_clean = dest
    end
    debug { "Copying #{src_clean}/ to #{dest_clean}/ with rsync -avz --delete" }
    result = Rsync.run(File.join(src_clean, '/'), File.join(dest_clean, '/'), ['-avz', '--delete'])
    if result.success?
      debug { "Rsync from #{src_clean}/ to #{dest_clean}/ successful" }
    else
      msg = "Failed to rsync from #{src_clean}/ to #{dest_clean}/: " + result.error
      raise Error, msg
    end
  else
    begin
      FileUtils.cp_r(src, dest, preserve: true)
    rescue Errno::ENOENT, Errno::EACCES
      debug do
        "Failed to copy from #{src} to #{dest} preserving file types, trying again without preserving them"
      end
      FileUtils.rm_rf(dest)
      FileUtils.cp_r(src, dest)
    end
  end
end

#debugObject



8
9
10
# File 'lib/librarian/puppet/util.rb', line 8

def debug(...)
  environment.logger.debug(...)
end

#infoObject



12
13
14
# File 'lib/librarian/puppet/util.rb', line 12

def info(...)
  environment.logger.info(...)
end

#module_name(name) ⇒ Object

get the module name from organization-module



73
74
75
76
# File 'lib/librarian/puppet/util.rb', line 73

def module_name(name)
  # module name can't have dashes, so let's assume it is everything after the last dash
  name.rpartition('-').last
end

#normalize_name(name) ⇒ Object

normalize module name to use organization-module instead of organization/module



68
69
70
# File 'lib/librarian/puppet/util.rb', line 68

def normalize_name(name)
  name.sub('/', '-')
end

#rsync?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/librarian/puppet/util.rb', line 20

def rsync?
  environment.config_db.local['rsync'] == 'true'
end

#warnObject



16
17
18
# File 'lib/librarian/puppet/util.rb', line 16

def warn(...)
  environment.logger.warn(...)
end