Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Preserve permissions when copying ruby gem to app

Change-Id: Ic3c3231c0d2957ddbc92bb7c3add1eb59778daea
  • Loading branch information...
commit bea999702edb867019bb6190ad7c9aec38864138 1 parent 92827cf
@mariash mariash authored
View
9 lib/vcap/staging/plugin/gemfile_task.rb
@@ -225,11 +225,10 @@ def copy_dir_contents(src, dest)
unsecure_file(src)
return unless src && File.exists?(src)
FileUtils.mkdir_p(dest)
- begin
- FileUtils.copy_entry(src, dest)
- rescue
- @logger.error "Failed copying gem to #{dest}"
- end
+ `cp -a #{shellescape(src)}/. #{shellescape(dest)}`
+ exitstatus = $?.exitstatus
+ @logger.error("Failed copying gem to #{dest}") if exitstatus != 0
+ exitstatus == 0
end
def installation_directory
View
2  lib/vcap/staging/plugin/gemspec_builder.rb
@@ -33,7 +33,7 @@ def update
end
def update_from_path(new_gemspec)
- FileUtils.copy_entry(new_gemspec, @gemspec_path)
+ FileUtils.copy_entry(new_gemspec, @gemspec_path, true)
rescue
@logger.error "Failed updating gemspec #{@gemspec_path}"
end
View
6 lib/vcap/staging/plugin/node/npm_support/npm_helper.rb
@@ -1,4 +1,4 @@
-require "shellwords"
+require File.expand_path("../../../secure_operations", __FILE__)
module NpmHelper
def get_npm_version
@@ -57,8 +57,4 @@ def unpack(what, where)
`#{cmd}`
$?.exitstatus
end
-
- def shellescape(word)
- Shellwords.escape(word)
- end
end
View
20 lib/vcap/staging/plugin/node/npm_support/npm_package.rb
@@ -1,7 +1,6 @@
require "fileutils"
require "uri"
require "net/http"
-require File.expand_path("../../../secure_operations", __FILE__)
require File.expand_path("../npm_helper", __FILE__)
# Node module class
@@ -84,7 +83,11 @@ def install_from_path(package_path)
def install_copy_from_path(package_path)
begin
tmp_dir = Dir.mktmpdir
- FileUtils.copy_entry(package_path, tmp_dir, true, nil, true)
+ `cp -a #{shellescape(package_path)}/. #{tmp_dir}`
+ if $?.exitstatus != 0
+ @logger.debug("Failed copying gem from path")
+ return nil
+ end
install_from_path(tmp_dir)
ensure
FileUtils.rm_rf(tmp_dir)
@@ -160,14 +163,11 @@ def get_cached_from_registry
def copy_to_dst(source)
return unless source && File.exists?(source)
FileUtils.rm_rf(@package_path)
- FileUtils.mkdir_p(File.dirname(@package_path))
- begin
- FileUtils.copy_entry(source, @package_path)
- return true
- rescue => e
- @logger.debug("Failed copying module to application #{e.message}")
- return false
- end
+ FileUtils.mkdir_p(@package_path)
+ `cp -a #{shellescape(source)}/. #{shellescape(@package_path)}`
+ exitstatus = $?.exitstatus
+ @logger.error("Failed copying module to application") if exitstatus != 0
+ exitstatus == 0
end
def build(where)
View
6 lib/vcap/staging/plugin/secure_operations.rb
@@ -1,3 +1,5 @@
+require "shellwords"
+
# This module contains methods for performing tasks and
# setting file permissions/ownership using a secure user
# Classes including this module should set the instance variable
@@ -87,4 +89,8 @@ def secure_group
group_name = `awk -F: '{ if ( $3 == #{@gid} ) { print $1 } }' /etc/group`
group_name.chomp
end
+
+ def shellescape(word)
+ Shellwords.escape(word)
+ end
end
View
2  spec/unit/gemspec_builder_spec.rb
@@ -8,7 +8,7 @@
@logger = double("Logger").as_null_object
git_gems_dir = app_fixture_base_directory.join("sinatra_git", "test_gem")
@working_dir = Dir.mktmpdir
- FileUtils.copy_entry(git_gems_dir, @working_dir)
+ FileUtils.copy_entry(git_gems_dir, @working_dir, true)
end
after :each do
View
2  spec/unit/npm_package_spec.rb
@@ -53,7 +53,7 @@
# copy_to_dst
app_source = app_fixture_base_directory.join("node_deps_native", "source")
app_test = File.join(@working_dir, "app")
- FileUtils.copy_entry(app_source, app_test)
+ FileUtils.copy_entry(app_source, app_test, true)
package_path = File.join(app_test, "node_modules", "bcrypt")
module_test = File.join(@working_dir, "module")
Please sign in to comment.
Something went wrong with that request. Please try again.