[DRE-commits] [librarian-puppet] 77/97: Issue #173 workaround, FileUtils.cp_r will fail if there is a symlink that points to a missing file

Stig Sandbeck Mathisen ssm at debian.org
Tue Mar 11 12:12:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit 656b7e1bfce96e39e25bc2a256f2778c4355b34a
Author: Carlos Sanchez <csanchez at maestrodev.com>
Date:   Wed Jan 29 17:40:38 2014 +0100

    Issue #173 workaround, 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
    
    fileutils.rb:1379:in `utime': No such file or directory
    /home/travis/build/rodjek/librarian-puppet/tmp/aruba/modules/postgresql/spec/acceptance/nodesets/default.yml (Errno::ENOENT)
    
    see also https://tickets.opscode.com/browse/CHEF-833
    
    Pin test modules versions
---
 features/install/forge.feature               | 10 ++++++----
 lib/librarian/puppet/source.rb               |  1 +
 lib/librarian/puppet/source/forge.rb         |  3 ++-
 lib/librarian/puppet/source/githubtarball.rb |  4 +++-
 lib/librarian/puppet/source/local.rb         |  3 ++-
 lib/librarian/puppet/util.rb                 | 27 +++++++++++++++++++++++++++
 6 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/features/install/forge.feature b/features/install/forge.feature
index 4c1919c..00516f5 100644
--- a/features/install/forge.feature
+++ b/features/install/forge.feature
@@ -80,21 +80,23 @@ Feature: cli/install/forge
     """
     forge "http://forge.puppetlabs.com"
 
-    mod 'puppetlabs/postgresql'
+    mod 'puppetlabs/postgresql', '3.2.0'
     """
     When I run `librarian-puppet install`
     Then the exit status should be 0
-    And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
+    And the file "modules/postgresql/Modulefile" should match /name 'puppetlabs-postgresql'/
+    And the file "modules/postgresql/Modulefile" should match /version '3\.2\.0'/
 
     Given a file named "Puppetfile" with:
     """
     forge "http://forge.puppetlabs.com"
 
-    mod 'puppetlabs/postgresql', :git => 'git://github.com/puppetlabs/puppet-postgresql'
+    mod 'puppetlabs/postgresql', :git => 'git://github.com/puppetlabs/puppet-postgresql', :ref => '3.3.0'
     """
     When I run `librarian-puppet install`
     Then the exit status should be 0
-    And the file "modules/postgresql/Modulefile" should match /name *'puppetlabs-postgresql'/
+    And the file "modules/postgresql/Modulefile" should match /name 'puppetlabs-postgresql'/
+    And the file "modules/postgresql/Modulefile" should match /version '3\.3\.0'/
 
   Scenario: Installing a module that does not exist
     Given a file named "Puppetfile" with:
diff --git a/lib/librarian/puppet/source.rb b/lib/librarian/puppet/source.rb
index 47a51d8..9f6d64e 100644
--- a/lib/librarian/puppet/source.rb
+++ b/lib/librarian/puppet/source.rb
@@ -1,3 +1,4 @@
+require 'librarian/puppet/util'
 require 'librarian/puppet/requirement'
 require 'librarian/puppet/source/path'
 require 'librarian/puppet/source/git'
diff --git a/lib/librarian/puppet/source/forge.rb b/lib/librarian/puppet/source/forge.rb
index fa1a100..5373af9 100644
--- a/lib/librarian/puppet/source/forge.rb
+++ b/lib/librarian/puppet/source/forge.rb
@@ -6,6 +6,7 @@ module Librarian
     module Source
       class Forge
         class Repo
+          include Librarian::Puppet::Util
 
           attr_accessor :source, :name
           private :source=, :name=
@@ -57,7 +58,7 @@ module Librarian
             unless unpacked_path.exist?
               raise Error, "#{unpacked_path} does not exist, something went wrong. Try removing it manually"
             else
-              FileUtils.cp_r(unpacked_path, install_path)
+              cp_r(unpacked_path, install_path)
             end
 
           end
diff --git a/lib/librarian/puppet/source/githubtarball.rb b/lib/librarian/puppet/source/githubtarball.rb
index db7a7f4..7872280 100644
--- a/lib/librarian/puppet/source/githubtarball.rb
+++ b/lib/librarian/puppet/source/githubtarball.rb
@@ -10,6 +10,8 @@ module Librarian
     module Source
       class GitHubTarball
         class Repo
+          include Librarian::Puppet::Util
+
           TOKEN_KEY = 'GITHUB_API_TOKEN'
 
           attr_accessor :source, :name
@@ -55,7 +57,7 @@ module Librarian
             end
 
             unpacked_path = version_unpacked_cache_path(version).children.first
-            FileUtils.cp_r(unpacked_path, install_path)
+            cp_r(unpacked_path, install_path)
           end
 
           def environment
diff --git a/lib/librarian/puppet/source/local.rb b/lib/librarian/puppet/source/local.rb
index 03b1d52..e180db2 100644
--- a/lib/librarian/puppet/source/local.rb
+++ b/lib/librarian/puppet/source/local.rb
@@ -2,6 +2,7 @@ module Librarian
   module Puppet
     module Source
       module Local
+        include Librarian::Puppet::Util
 
         def install!(manifest)
           manifest.source == self or raise ArgumentError
@@ -41,7 +42,7 @@ module Librarian
 
         def install_perform_step_copy!(found_path, install_path)
           debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
-          FileUtils.cp_r(found_path, install_path, :preserve => true)
+          cp_r(found_path, install_path)
         end
 
         def manifest?(name, path)
diff --git a/lib/librarian/puppet/util.rb b/lib/librarian/puppet/util.rb
new file mode 100644
index 0000000..9a54f95
--- /dev/null
+++ b/lib/librarian/puppet/util.rb
@@ -0,0 +1,27 @@
+module Librarian
+  module Puppet
+
+    module Util
+
+      def debug(*args, &block)
+        environment.logger.debug(*args, &block)
+      end
+      def info(*args, &block)
+        environment.logger.info(*args, &block)
+      end
+
+      # 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 https://tickets.opscode.com/browse/CHEF-833
+      def cp_r(src, dest)
+        begin
+          FileUtils.cp_r(src, dest, :preserve => true)
+        rescue Errno::ENOENT
+          debug { "Failed to copy from #{src} to #{dest} preserving file types, trying again without preserving them" }
+          FileUtils.rm_rf(dest)
+          FileUtils.cp_r(src, dest)
+        end
+      end
+    end
+  end
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list