Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Bug 976112
Browse files Browse the repository at this point in the history
In setup_rewritten, we need to process all file types.
  • Loading branch information
BanzaiMan committed Jun 26, 2013
1 parent 148ca2c commit 6f5bf7c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
13 changes: 9 additions & 4 deletions node/lib/openshift-origin-node/utils/managed_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module ManagedFiles
# cart - the cartridge you wish to query
# type - the key you wish to obtain
# process_files - whether or not to process the files before returning
# files_only - whether or not only files are processed (i.e., no symlinks, directories). default is true
#
# If process_files is true, the following actions are taken on the array:
# - relative entries are chrooted to the user's home directory or cartridge
Expand All @@ -51,7 +52,7 @@ module ManagedFiles
#
# Returns an <code>Array</code> containing file names or strings
# - If these entries are processed, they are returned relative to the user's home directory
def managed_files(cart, type, root, process_files = true)
def managed_files(cart, type, root, process_files = true, files_only = true)
# Ensure that root ends in a slash
root = "#{PathUtils.join(root,'')}/"
# TODO: Is it possible to get a cart's full directory path?
Expand Down Expand Up @@ -89,7 +90,11 @@ def managed_files(cart, type, root, process_files = true)
wanted_files = good_patterns.map do |pattern|
if pattern =~ /\*/
# Ensure only files are globbed and not dirs
Dir.glob(pattern, File::FNM_DOTMATCH).select{ |f| File.file?(f) }
if files_only
Dir.glob(pattern, File::FNM_DOTMATCH).select{ |f| File.file?(f) }
else
Dir.glob(pattern)
end
else
# Use all explicit patterns
pattern
Expand Down Expand Up @@ -149,9 +154,9 @@ def snapshot_exclusions(cartridge)
#
# cartridge - the cartridge you wish to query
#
# Returns an array of matching file entries.
# Returns an array of all matching entries, including non-files
def setup_rewritten(cartridge)
managed_files(cartridge, :setup_rewritten, @user.homedir)
managed_files(cartridge, :setup_rewritten, @user.homedir, true, false)
end

# Obtain the 'restore_transforms' entry from the managed_files.yml file
Expand Down
25 changes: 25 additions & 0 deletions node/test/unit/managed_files_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def touch_files(files)
end
end

# create symlink in @cartridge.directory
# 'files' should be a Hash {link => target, ...}
def symlink_files(files)
files.each do |link, path|
target = File.join(@user.homedir, @cartridge.directory, path)
sl = File.join(@user.homedir, @cartridge.directory, link)
dir = File.dirname(target)
linkdir = File.dirname(sl)
FileUtils.mkdir_p(dir)
FileUtils.mkdir_p(linkdir)
FileUtils.ln_sf(target, sl)
end
end

# Transform relative file paths
def chroot_files(files)
files.map do |x|
Expand Down Expand Up @@ -87,6 +101,17 @@ def test_block_immutable_files
end
end

def test_setup_rewritten
src = 'this/file'
link = 'this/link'
touch_files [src]
symlink_files link => src

set_managed_files({:setup_rewritten => ['this/**/*']})

assert_equal %w(mock/this/file mock/this/link).sort, setup_rewritten(@cartridge).sort
end

# Ensure locked_files does not return bad entries
def test_get_locked_files_static
good_files = %w(~/.good ~/app-root/good good ~/app-root/foo/good/) << "~/#{@cartridge.directory}/good"
Expand Down

0 comments on commit 6f5bf7c

Please sign in to comment.