Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
Preserve permissions when copying ruby gem to app
Browse files Browse the repository at this point in the history
Change-Id: Ic3c3231c0d2957ddbc92bb7c3add1eb59778daea
  • Loading branch information
mariash committed Oct 5, 2012
1 parent 92827cf commit bea9997
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
9 changes: 4 additions & 5 deletions lib/vcap/staging/plugin/gemfile_task.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/vcap/staging/plugin/gemspec_builder.rb
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions 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
Expand Down Expand Up @@ -57,8 +57,4 @@ def unpack(what, where)
`#{cmd}`
$?.exitstatus
end

def shellescape(word)
Shellwords.escape(word)
end
end
20 changes: 10 additions & 10 deletions 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions 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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/unit/gemspec_builder_spec.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/npm_package_spec.rb
Expand Up @@ -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")
Expand Down

0 comments on commit bea9997

Please sign in to comment.