From: Ashley Penney Date: Wed, 5 Mar 2014 18:16:24 +0000 (-0500) Subject: Merge pull request #260 from daenney/zomg-ze-chars X-Git-Tag: 1.5.0~29 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=791be559ba65f76ab586adf4a7e6675ce95b3197;hp=ab6f6d31468ae865d1ff8ba7ec108802d5b27625;p=puppet-modules%2Fpuppetlabs-apt.git Merge pull request #260 from daenney/zomg-ze-chars pin: Replace invalid chars with _ in file names. --- diff --git a/manifests/pin.pp b/manifests/pin.pp index 9cb4a8e..0d4d742 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -68,7 +68,17 @@ define apt::pin( '' => "${preferences_d}/${name}.pref", default => "${preferences_d}/${order}-${name}.pref", } - file { "${name}.pref": + + # According to man 5 apt_preferences: + # The files have either no or "pref" as filename extension + # and only contain alphanumeric, hyphen (-), underscore (_) and period + # (.) characters. Otherwise APT will print a notice that it has ignored a + # file, unless that file matches a pattern in the + # Dir::Ignore-Files-Silently configuration list - in which case it will + # be silently ignored. + $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG') + + file { "${file_name}.pref": ensure => $ensure, path => $path, owner => root, diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index f1ca437..6438e8c 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -105,4 +105,16 @@ describe 'apt::pin', :type => :define do } end end + + describe 'resource title with invalid chars' do + context 'spaces' do + let(:title) { 'oh my god this is not valid' } + it { should contain_file('oh_my_god_this_is_not_valid.pref') } + end + + context '#$&*$' do + let(:title) { 'so && many $* invalid @! things' } + it { should contain_file('so____many____invalid____things.pref') } + end + end end