Skip to content

Commit

Permalink
chdir before globbing so that we don't need to escape directory names.
Browse files Browse the repository at this point in the history
fixes #5521
  • Loading branch information
tenderlove committed Mar 23, 2012
1 parent e944b29 commit 7422f44
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion railties/lib/rails/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,25 @@ def expanded
path = File.expand_path(p, @root.path)

if @glob
result.concat Dir[File.join(path, @glob)].sort
if File.directory? path
result.concat expand_dir(path, @glob)
else
# FIXME: I think we can remove this branch, but I'm not sure.
# Say the filesystem has this file:
#
# /tmp/foobar
#
# and someone adds this path:
#
# /tmp/foo
#
# with a glob of "*", then this function will return
#
# /tmp/foobar
#
# We need to figure out if that is desired behavior.
result.concat expand_file(path, @glob)
end
else
result << path
end
Expand All @@ -177,6 +195,17 @@ def existent_directories
end

alias to_a expanded

private
def expand_file(path, glob)
Dir[File.join(path, glob)].sort
end

def expand_dir(path, glob)
Dir.chdir(path) do
Dir.glob(@glob).map { |file| File.join path, file }.sort
end
end
end
end
end

0 comments on commit 7422f44

Please sign in to comment.